I was just wondering, whats the difference between,



push 10h
push offset MESSAGECAP
push offset MESSAGETEXT
push 0
Call MessageBoxA

Just wondering which one is more common/preferred. Yes I'm a newbie to Assembly programming but have some good XP with softice and Dasm
Posted on 2004-02-17 18:09:20 by akuma6099
ADDR generally translates to :

push eax

The invoke macro just makes your code a little bit more lisible.. which comes in handy.. especially after seeing some API's like CreateFont :)

Generally the rule is.. that if your strings , buffers, etc are declared in .data or .data? you should use Offset which translates to:


ADDR should only be used for local variables which you declare upon entry on your proc using the LOCAL statement

Hope this helps,
Posted on 2004-02-17 18:35:22 by JimmyClif
You can use the /Sg switch on the MASM command line to see (in the .LST file) the code generated by INVOKE .IF etc. :)
Posted on 2004-02-17 18:53:46 by S/390
ADDR generally translates to :

push eax

Last time I looked, it only did that for local vars, and used offset for globals.
Posted on 2004-02-17 19:35:05 by Henk-Jan

Last time I looked, it only did that for local vars, and used offset for globals.

to be honest i never looked :tongue:

now you're forcing me to look... if that is so then addr is smarter than i expected

jimmy :alright:
Posted on 2004-02-17 19:55:45 by JimmyClif
Thanks for the insight everybody. I've managed to figure out how to use API's in VB.NET which is the reason why I switched to Assembly(more than that). but I know I could do more with Assembly just by reading a few tutorials. It lets me get down to the nitty-gritty. I only used VB.NET due to college courses and that was a breeze so I'm up for another challenge.:alright:
Posted on 2004-02-17 21:35:26 by akuma6099
Yes ADDR is replaced by OFFSET when the variable is not local but that is the only good thing about it. ADDR is dumb and should be considered a bug in MASM when used in an invoke, there are places for LEA, for example when moving a local address into a register but in invoke it screws with eax and that is just wrong. You can always use :


PUSH [EBP-4] ; Local DWORD 1
PUSH [EBP-8] ; Local DWORD 2

ADD [ESP],-4 ; Offset local DWORD 1
ADD [ESP],-8 ; Offset local DWORD 2

There is no need to flub around with LEA and trash EAX for no good reason at all. Just try this:

invoke GetDlgItem,[hwnd],1001

invoke SendMessage,eax,WM_GETTEXT,256,ADDR buffer

and you'll see what I mean, it's just plain dumb.
Posted on 2004-02-18 01:03:21 by donkey