INVOKE
Visual Studio 2010
Calls the procedure at the address given by expression, passing the arguments on the stack or in registers according to the standard calling conventions of the language type.
INVOKE expression [[, arguments]]
Example using INVOKE vs calling the function manually
Here is an example calling printf using both INVOKE and doing the call manually
; #########################################################################
; Explore assembly , learning Macro Assembly for Microsoft X86
; #########################################################################
.386
.model flat,C ; 32 bit memory model
option casemap :none ; Case sensitive
; #########################################################################
.data
fmt db "Result is %d",13,10,0
szHello db "Hello World %d",13,10,0
.code
includelib MSVCRT
; Prototype needed by INVOKE
printf PROTO arg1:Ptr Byte, printlist: VARARG
wmain proc PUBLIC
;==============
; Locals on the stack
;==============
LOCAL idx :DWORD
LOCAL cnt :DWORD
LOCAL clBuffer[128] :BYTE
;==============
; Initialize
;==============
mov idx,1000
mov cnt,0
.WHILE idx > 0
sub idx,1
add cnt,2
INVOKE printf,ADDR fmt,cnt
.ENDW
; Here we use the old fashioned way of manually setting up the stack, calling the function, then cleaning up the stack
; In the loop above all we had to do was use INVOKE which handles this for us
push 1
push offset szHello
call printf
add esp,8
xor eax,eax
ret
wmain endp
END
I have a more examples at hybridmachine.com : http://www.hybridmachine.com/wp-content/uploads/2012/03/explore_masm.zip
; #########################################################################
; Explore assembly , learning Macro Assembly for Microsoft X86
; #########################################################################
.386
.model flat,C ; 32 bit memory model
option casemap :none ; Case sensitive
; #########################################################################
.data
fmt db "Result is %d",13,10,0
szHello db "Hello World %d",13,10,0
.code
includelib MSVCRT
; Prototype needed by INVOKE
printf PROTO arg1:Ptr Byte, printlist: VARARG
wmain proc PUBLIC
;==============
; Locals on the stack
;==============
LOCAL idx :DWORD
LOCAL cnt :DWORD
LOCAL clBuffer[128] :BYTE
;==============
; Initialize
;==============
mov idx,1000
mov cnt,0
.WHILE idx > 0
sub idx,1
add cnt,2
INVOKE printf,ADDR fmt,cnt
.ENDW
; Here we use the old fashioned way of manually setting up the stack, calling the function, then cleaning up the stack
; In the loop above all we had to do was use INVOKE which handles this for us
push 1
push offset szHello
call printf
add esp,8
xor eax,eax
ret
wmain endp
END
I have a more examples at hybridmachine.com : http://www.hybridmachine.com/wp-content/uploads/2012/03/explore_masm.zip
- 3/2/2012
- hybridmachine