Hi, I'm new MASM, therefore I have a few questions...
I'm trying to keep track of some values as they go through a series of calculations, so I kept 'print' ing out the value as they went through each step but kept coming out with some very strange numbers so I experimented with all the GP registers and confirmed my suspicions. What I'm asking is, is there a fix for this, which include file has the print and str$ macros? or am I just doing it all wrong and need to use some other instruction?
The experiment code is as follows:
mov eax, 16
mov ebx, 32
mov ecx, 64
mov edx, 128
mov esi, 256
mov edi, 512
print str$(eax)
print str$(ebx)
print str$(ecx)
print str$(edx)
print str$(esi)
print str$(edi)
print chr$(13, 10)
print str$(eax)
print str$(ebx)
print str$(ecx)
print str$(edx)
print str$(esi)
print str$(edi)
exit
What I expected was:
16
32
64
128
256
512
16
32
64
128
256
512
But instead I got:
16
32
2011667995
1
256
512
2
32
2011667995
1
256
512
Leaving the only general purpose registers that can be used for print and calculations are, ebx, esi, and edi.
Is this right?
Thank you in advance for any help
Wez
QuoteLeaving the only general purpose registers that can be used for print and calculations are, ebx, esi, and edi.
Is this right?
Absolutely right. Windows API and MASM32 functions are expected to (and usually do) preserve the ebx, esi and edi registers. However, the EAX, ECX and EDX registers are considered free to be trashed. Whenever you need to preserve such registers, you need to save them
before you call external functions and restore them when you need them. For example,
push edx
push ecx
print str$(eax)
print str$(ebx)
pop ecx
print str$(ecx)
pop edx
print str$(edx)
Raymond
Wez,
For more information see \masm32\help\asmintro.hlp: Register Preservation Convention.
Thanks guys, isn't it easy when you know how.
Wez :bg