0

I was wondering if there was any advantage of passing arguments to functions using stack, in assembly language. Here is what I mean:

readString PROTO :DWORD ;Prototype for function
;Now we call the function by moving a DWORD value into eax and pushing eax
mov eax, FAD37EABh
push eax
CALL readString

Is there any advantage of using this method over the following?

INVOKE readString, FAD37EABh

Regards,

Devjeet

devjeetroy
  • 1,855
  • 6
  • 26
  • 43

2 Answers2

1

Not really; invoke is basically just a built-in macro that will expand to pretty much the same code anyway.

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111
  • 1
    @devjeetroy: I generally prefer `invoke` syntax, but there are people who disagree. Windows code, in particular, gets really *long* if you do all the pushes explicitly (e.g., a single call to CreateFile ends up ~20 lines long). – Jerry Coffin May 02 '11 at 04:21
1

No, there's no difference in the final code, but it is very convenient. It's a macro which automatically checks if arguments type match, therefore helping you spotting errors. Of course, invoke readString, eax or push eax; call readString are almost the same, but suppose you need to call Win32'a API with their thousands of parameters:

    push NULL
    push hInst
    push NULL
    push NULL
    push 200
    push 300
    push CW_USEDEFAULT
    push CW_USEDEFAULT
    push WS_OVERLAPPEDWINDOW
    push addr Appame
    push addr Classame
    push WS_EX_CLIENTEDGE
    call CreateWindowEx
    INVOKE CreateWindowEx,WS_EX_CLIENTEDGE,ADDR ClassName,ADDR AppName,\
           WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\
           CW_USEDEFAULT,300,200,NULL,NULL,\
           hInst,NULL

In this case uning invoke is much more helpful and readable.

BlackBear
  • 22,411
  • 10
  • 48
  • 86