flat assembler
Message board for the users of flat assembler.
Index
> Windows > what does LocalAlloc,LMEM_FIXED do with a register |
Author |
|
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. |
|||
09 Feb 2005, 18:17 |
|
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 ?? |
|||
10 Feb 2005, 17:14 |
|
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 |
|||
10 Feb 2005, 18:04 |
|
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 |
|||
10 Feb 2005, 18:18 |
|
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" |
|||
10 Feb 2005, 18:54 |
|
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 |
|||
10 Feb 2005, 20:43 |
|
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. |
|||
11 Feb 2005, 00:00 |
|
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 |
|||
11 Feb 2005, 08:22 |
|
gumletis 11 Feb 2005, 15:34
anybody?
|
|||
11 Feb 2005, 15:34 |
|
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] |
|||
11 Feb 2005, 17:41 |
|
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 |
|||
11 Feb 2005, 20:15 |
|
gumletis 11 Feb 2005, 22:07
anyone?
|
|||
11 Feb 2005, 22:07 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.