Why is edx changed during a call? This small snippet shows everything except the expected output 12345d.....
mov edx, 12345d
call ShowEDX
ret
ShowEDX:
invoke wsprintf, addr bff, S('%i'), edx
invoke MessageBox, 0h, addr bff, addr bff, 0h
ret
The other registers eax, ebx, ecx are working...can anyone explain...?
And please remind me: esi & edi never change during a simple call, do they?
Dominik
mov edx, 12345d
call ShowEDX
ret
ShowEDX:
invoke wsprintf, addr bff, S('%i'), edx
invoke MessageBox, 0h, addr bff, addr bff, 0h
ret
The other registers eax, ebx, ecx are working...can anyone explain...?
And please remind me: esi & edi never change during a simple call, do they?
Dominik
.data
caption db 'wsprintf example',0
format1 db '%d',0
.data?
buffer db 6 dup(?)
.code
start:
mov edx, 12345
call ShowEDX
invoke ExitProcess,0
ShowEDX:
invoke wsprintf,ADDR buffer,ADDR format1,edx
invoke MessageBox,0,ADDR buffer,ADDR caption,MB_OK
ret
END start
The EAX, ECX and EDX registers are "scratch" for the stdcall calling convention. This means functions following this conv. (like the APIs, for example) don't need to preserve their values after on return.
I'm sure there's a whole thread on this in the FAQ section, just look it up (or do a board search). :)
I'm sure there's a whole thread on this in the FAQ section, just look it up (or do a board search). :)
thx for re-coding, vortex (->sense?)
ok QvasiModo, i will have a look....thx for the reference!
Dominik
ok QvasiModo, i will have a look....thx for the reference!
Dominik
Sorry Dom, I misunderstood your question, you can ignore my previous post.
NoProb :wink:
Dom,
Your main question was:
The 2nd parameter required with the wsprintf function must be a pointer to the format-control string. You were using S('%i') which seems to be a macro of some kind to generate a string and insert its address as the 2nd parameter. The macro instructions would be inserted in your code immediately before the call and may be responsible for trashing the EDX register. The call instruction itself does NOT trash any register.
You could experience something similar with the INVOKE "macro" if you use EAX as one of the parameters and also use the "ADDR xxx" of a local variable as another parameter. The EAX register gets trashed by the ADDR macro for local variables but not for global variables.
Raymond
Your main question was:
The other registers eax, ebx, ecx are working...can anyone explain...?
The 2nd parameter required with the wsprintf function must be a pointer to the format-control string. You were using S('%i') which seems to be a macro of some kind to generate a string and insert its address as the 2nd parameter. The macro instructions would be inserted in your code immediately before the call and may be responsible for trashing the EDX register. The call instruction itself does NOT trash any register.
You could experience something similar with the INVOKE "macro" if you use EAX as one of the parameters and also use the "ADDR xxx" of a local variable as another parameter. The EAX register gets trashed by the ADDR macro for local variables but not for global variables.
Raymond
Thx Raymond...you were right!
I tested the value in edx using cmp-jmp intructions and it still holds the initial value. The prob was I used several macros internally that did mess up edx, though not eax (cause my macro preserves it), ebx, ....
The EAX register gets trashed by the ADDR macro for local variables but not for global variables.
Great Info -> thanks alot...
Dominik
I tested the value in edx using cmp-jmp intructions and it still holds the initial value. The prob was I used several macros internally that did mess up edx, though not eax (cause my macro preserves it), ebx, ....
The EAX register gets trashed by the ADDR macro for local variables but not for global variables.
Great Info -> thanks alot...
Dominik
At times like this try using this:
ml /Fllist.txt /Sa /Sn my_asm.asm
It'll generate a file called list.txt which contains the byte sequence, code, and expanded macros for your code.
Mirno
ml /Fllist.txt /Sa /Sn my_asm.asm
It'll generate a file called list.txt which contains the byte sequence, code, and expanded macros for your code.
Mirno