flat assembler
Message board for the users of flat assembler.

Index > Windows > what does LocalAlloc,LMEM_FIXED do with a register

Author
Thread Post new topic Reply to topic
gumletis



Joined: 18 Dec 2004
Posts: 128
gumletis 09 Feb 2005, 12:55
Hi, i have use the LocalAlloc to set up a register to be like a reserved byte, but how do i do this with interrupts? or just even mov/add instructions? and can it be done

ps this is how i did

invoke LocalAlloc,LMEM_FIXED,100
mov edx,eax


just for getting edx with 100 maxmimum symbols

_________________
LOOOL
Post 09 Feb 2005, 12:55
View user's profile Send private message Reply with quote
beppe85



Joined: 23 Oct 2004
Posts: 181
beppe85 09 Feb 2005, 18:17
LocalAlloc will return you a pointer to an area you can use. It will return a different results each time

If you only need one such area, you can do a "rd":

; this needs a static size, like 100 is
my_stuff: rd 100

If you need a dynamic ize, you can grab some from stack
sub esp, size
; your area is pointed by esp

Or plz explain it a bit more.
Post 09 Feb 2005, 18:17
View user's profile Send private message Reply with quote
gumletis



Joined: 18 Dec 2004
Posts: 128
gumletis 10 Feb 2005, 17:14
hmm, thinks that is what i need, but just donno how the full code should be, should it be like this?

sub esp,100
mov edi,esp


would that reserve some space i can use in edi(100) ?? or should i do like this

sub esp,100
lea edi,esp

would it be almost the same as

invoke LocalAlloc,LMEM_FIXED,100
mov edi,eax

??
Post 10 Feb 2005, 17:14
View user's profile Send private message Reply with quote
beppe85



Joined: 23 Oct 2004
Posts: 181
beppe85 10 Feb 2005, 18:04
There's no definitive answer...LocalAlloc is more general and should fit everywhere. You already using this correctly. Rememberto free this memory when you no longer need. Ex:

invoke LocalFree, edi

The stack approch is faster, and simple to dealloc. But you hardly could resize the block, because you free a block on stack all in one place. I recommend you to use ebp. Ex:

push ebp
mov ebp, esp
sub esp,100
mov edi,esp
...
; use block pointed by edi
...
; this will automatically free all memory
mov esp, ebp
pop ebp
Post 10 Feb 2005, 18:04
View user's profile Send private message Reply with quote
gumletis



Joined: 18 Dec 2004
Posts: 128
gumletis 10 Feb 2005, 18:18
do i need to do that, can i not just free it with

mov edi,0x0

or

xor edi,edi

:p ? i know im weird :-s
Post 10 Feb 2005, 18:18
View user's profile Send private message Reply with quote
beppe85



Joined: 23 Oct 2004
Posts: 181
beppe85 10 Feb 2005, 18:54
No, you will not free with that...but you still can put it after LocalFree, so you can check for a null. If you leave the register unchanged, you could dereference a no more valid pointer. This is a phenomenon known as pointer dangling.

PS: when alloc'ing on stack, you just put "xor reg, reg", all blocks will be freed by the "mov esp, ebp"
Post 10 Feb 2005, 18:54
View user's profile Send private message Reply with quote
gumletis



Joined: 18 Dec 2004
Posts: 128
gumletis 10 Feb 2005, 20:43
what about this, why wont that work

Code:
org 0x100
sub sp,128
mov dx,sp
mov ah,0x1a
mov ax,dx
int 0x21
mov ah,0x4e
mov cx,0x3f
mov dx,place
int 0x21
mov si,ax+30
mov ah,0xe
reply:
lodsb
int 0x10
loop reply
RET
place db 'c:\winnt\*.*',0



    
still only a test
Post 10 Feb 2005, 20:43
View user's profile Send private message Reply with quote
beppe85



Joined: 23 Oct 2004
Posts: 181
beppe85 11 Feb 2005, 00:00
If you mean won't compile, there is no such instruction for "mov si, ax+30". Try lea si, [ax+30]. But I don't know 16bit very well, so you must test.

PS: can I ask a favour to you? please give detailed information about errors and what you intended to do, you'll get fast answers.
Post 11 Feb 2005, 00:00
View user's profile Send private message Reply with quote
gumletis



Joined: 18 Dec 2004
Posts: 128
gumletis 11 Feb 2005, 08:22
shall not be a favour, MY BAD, heres what its says error(ps i've have tryed so many things, like mov si,word[ax+30] and such things, but doesn't work)

mov si,ax+30 = says extra charactor line
lea si,[ax+30] = says reserved word used as symbol


hope this helps you a bit

_________________
LOOOL
Post 11 Feb 2005, 08:22
View user's profile Send private message Reply with quote
gumletis



Joined: 18 Dec 2004
Posts: 128
gumletis 11 Feb 2005, 15:34
anybody?
Post 11 Feb 2005, 15:34
View user's profile Send private message Reply with quote
beppe85



Joined: 23 Oct 2004
Posts: 181
beppe85 11 Feb 2005, 17:41
Oh yeah ax cannot be used as base.

mov si, ax
add si, 30

or instead of ax use other:
lea si, [bx+30]
Post 11 Feb 2005, 17:41
View user's profile Send private message Reply with quote
gumletis



Joined: 18 Dec 2004
Posts: 128
gumletis 11 Feb 2005, 20:15
i can't understand why this wont work.

Code:
org 0x100
sub sp,128
mov dx,sp
mov ah,0x1a
mov bx,dx
int 0x21
mov ah,0x4e
mov cx,0x3f
mov dx,place
int 0x21
call print
mov ah,0x4f
mov dx,place
mov ah,4fh
loopy:
int 0x21
jnc loopy
RET
place db 'c:\winnt\*.*',0
imhere db 'im here$',0
print:
lea si,[bx+30]
mov ah,0xe
reply:
lodsb
int 0x10
loop reply
mov ah,0x9
mov al,13
int 0x10
mov al,10
int 0x10
mov ah,0x0
int 0x16
RET       

ps i was reading a tutorial and wrote down my own pieces of code, but doesn't work.

_________________
LOOOL
Post 11 Feb 2005, 20:15
View user's profile Send private message Reply with quote
gumletis



Joined: 18 Dec 2004
Posts: 128
gumletis 11 Feb 2005, 22:07
anyone?
Post 11 Feb 2005, 22:07
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.