flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > addresses of locals

Author
Thread Post new topic Reply to topic
asimov



Joined: 04 Feb 2005
Posts: 4
asimov
Forgive me if this sounds stupid, but I am trying to pass the address of a variable which is declared using the locals macro. The cut down section of the code is:
proc init,.seg,.dat,.keybytes
locals
.ldat rd 2
endl
begin
mov bx,ss
movzx eax,bx ; move stack segment into eax for push
stdcall subroutine,eax,.ldat,1
return
endp

However, I get an 'invalid argument' error in the pushd instruction

What have I missed, or is it not possible to pass addresses of locals?

Also, is there a macro for pushing and retrieving entire segment:offset (16:32 format) pointers when passing them as arguments?

Thanks.

Matthew.
Post 21 Feb 2005, 21:53
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
asimov wrote:
What have I missed, or is it not possible to pass addresses of locals?


You missed that the address of local variable is not a constant, but relative to the register ebp i.e. ".ldat" == "ebp+const".
So, there is no push instruction that can push this address directly. Use "lea" instruction instead:
Code:
    lea   ecx, [.ldat]
    stdcall subroutine, eax, ecx, 1 
    


For example MASM allows directly pushing of local variables in the "invoke" macro, but it uses eax and mutually do the same "lea eax, ldat | push eax".
I think that using "lea" is more readable.

Regards.
Post 21 Feb 2005, 23:18
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
asimov



Joined: 04 Feb 2005
Posts: 4
asimov
Thanks for the reply. I got it now Smile Duh, should have thought of that!
Post 22 Feb 2005, 18:34
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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.