I have this piece of code, how would I use push/pop on it?


INVOKE TranslateMessage, ADDR msg
INVOKE DispatchMessage, ADDR msg

I tried


push offset msg
call TranslateMessage

push offset msg
call DispatchMessage

But I get 'error A2098: invalid operand for OFFSET'

Also, is using push/pop faster then invoke? and how do I set the stack size.
Posted on 2003-06-05 09:15:48 by KewLexX
invoke makes use of pushes

INVOKE TranslateMessage, ADDR msg 

becomes
lea eax,msg

push eax
call TranslateMessage

Your error is probably due to the fact that msg is a local variable.

Define what you mean by stack size.
You can change stack size by
changing dword ptr fs:[4] and dword ptr fs:[8]
Posted on 2003-06-05 09:38:09 by roticv
KewLexX,

You won't find it any more concise than the following. Ratch



.686
.MMX
.K3D
.XMM
.MODEL FLAT,STDCALL
option casemap :none ; case sensitive

= OFFSET @ EQU OFFSET

.LISTMACROALL
; #########################################################################
.NOLIST
.LIST
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\gdi32.lib

00000000 .DATA?
00000000 .DATA
00000000 00000004 DD 4,5,6
00000005
00000006
0000000C 54 48 49 53 20 msg DB "THIS IS A MESSAGE",0
49 53 20 41 20
4D 45 53 53 41
47 45 00
0000001E 07 08 09 DB 7,8,9
00000000 .CODE
.LISTALL
00000000 START:
INVOKE TranslateMessage,@ msg
00000000 68 0000000C R * push dword ptr OFFSET FLAT:msg
00000005 E8 00000000 E * call TranslateMessage
INVOKE DispatchMessage, @ msg
0000000A 68 0000000C R * push dword ptr OFFSET FLAT:msg
0000000F E8 00000000 E * call DispatchMessageA
END START
Posted on 2003-06-05 10:20:07 by Ratch
that was extrange for me....

Ok, i need say that some guy near the computer close thereply that i was writing, then i will reply but a little less...


push dword[esp+4] ;valid, you are pushing the content(value) in the address esp+4
push dword esp+4 ;invalid, you are trying push the direction esp+4
push dword[ebp+4] ;VALID, you are pushing the content(value) in the addres ebp+4
push dword ebp+4 ;INVALID, pushing the address ebp+4
push eax+4 ;Invalid, yu are trying push eax+4 i later explain a little
lea eax, ebp+4 ;invalid, you are trying load in eax the efective address of ebp+4 (that is other address)
lea eax, [ebp+4] ; you are loading the effective address of ebp+4... (i explain later)
mov eax, [ebp] ;valid



First:

The assembler any assembler can calculate some things and others cant, the thing that can calculate is the size of structures, the offset or displacement of a label in a section (.data, .code), you provide onlyothers constant values, like:

invoke aFunction, NULL, 23, "hola Mundo"

in the case above, "hola mundo" is in the data section and the offset is pushed to the stack. NULL is 0, 23 is another constant, and aFunciton is too a constant, for example, ii you have:



x dd 1
aFunction proc
endp
afunction have the value 4 [i](in the instruction pointer,
starting at 0, because at 0 are reserved 4 bytes)[/i]

Like you see, the assembler can only manipulate values that can know his content, or the value, or the constant.
All the other values are calculated in the run-time. This values are addres maybe other things...



for example.. maybe you now are questioning, the for what this:


push dword[esp+4]


is valid and this


push dword esp+4


no

the answer is:


push dword[esp+4] ; [i]you are only pushing the value at esp+4,
;that can only know in the run-time, but is the content[/i].


push dword esp+4 , you are pushing the value of esp and a addition, like you see, you are pushing the direction pointed by esp+4 ;that cannot be know in the asemble time, but in the run-time too cannot be know.. why?, is for example esp can point to 2000, 300 or any other number, and you can push this value.. try..

push esp

now what append if you push esp+4, you are saying that you want to push the address plus 4, like you see no is the same that push dword in this case you are only saying that you want the value at that direction, in words, you only want one operation (get the value at that direction), but in push dword esp+4 you are saying that you whan push the address plus 4, then in words is 2 instruction, the push instruction can manipulate only one instruction.

then, lea (load effective address) can load complex address, that can not be calculated in the assembly-time and that can not be calculated in run-time in one instruction like push esp.

now, addr se firts if the var that you are working is local or is definied for example in the data section or other section.. this is can be calculated be the assembler, if is this, only is converted in push var, but if the var is a local variable, it do two operations:


lea eax, [esp+4]
push eax ;only one value

lea can be replaced, only for catch a little more what do lea..


mov eax, esp
add eax,4

like you see esp can have the addres 2000,3000, and you can add 4 (bytes) to this addres, and you have the direction 2004, now you can push easely this addres.. push eax, or push the content at that addres push dword


The code of Ratch work with offset (@) only for msg is definied in the data section of the file


I think that was a little large, but i hope this can help you.

If I confuse you, or my english still to bad, let us know. :D

Nice day.
Posted on 2003-06-05 11:45:01 by rea