My code does not generate what I expect it to, code follows below
include \masm32\include\masm32rt.inc
.code
start:
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
main proc
LOCAL holder :DWORD
xor eax, eax
xor edx, edx
mov eax, 5
mov edx, 3
print ustr$(eax),13,10,13,10
print ustr$(edx),13,10,13,10
print ustr$(eax),13,10,13,10
print ustr$(edx),13,10,13,10
print ustr$(eax),13,10,13,10
add eax, edx
print ustr$(eax),13,10,13,10
inkey
ret
main endp
exit
end start
And this is the output:
5
582600
4
582600
4
582604
But I expect the following output
5
3
5
3
5
8
What am I doing wrong?
print ustr$(eax),13,10,13,10
The value in eax (and edx) is likely changed by the ustr$ macro.... And also by the print macro....
push eax
push edx
print ustr$(eax),13,10,13,10
pop edx
pop eax
push eax
push edx
print ustr$(edx),13,10,13,10
pop edx
pop eax
etc etc
This will work.... Alternatively use the ebx, esi, edi registers as these are preserved by the macros
However if you do this also:
main proc USES ebx esi edi
Thank you, that explained it all.
Where do I find the source-code for the MASM32-macros? I'm using version 10 and I searched the files in the macros folder but I couldn't seem to find the macros I searched for. For example the rv-macro (return value).
\masm32\macros\macros.asm
Search for *macroname* *space* 'macro'
ie
'rv macro'
(In most if not all cases you should find what you are looking for however remember also other whitespace characters may exist ie tab)
the source code is in \masm32\macros\macros.asm
there is also a help file \masm32\help\hlhelp.chm
Ani,
The thing you need to learn is the register preservation convention, commonly known as the Intel ABI (Application Binary Interface), in the ordinary sense, you can modify EAX ECX EDX but must ensure that EBX ESI EDI remain the same. If you are layout out a procedure manually you must also preserve EBP and ESP. The function behind the macros all use this convention and it is important to get it right.
Now if you swapped the EAX and EDX registers in your example to ESI and EDI, the functions that are called must preserve them so you don't have to between function calls.
As a side note..
Quote
xor eax, eax
xor edx, edx
mov eax, 5
mov edx, 3
You can do away with the XORs, as the registers are overwritten with the MOVs
:wink