Page 1 of 1

What happens with rxc and edx registers during procedure execution? (listing2-2)

Posted: Sun Jan 05, 2025 12:28 pm
by sahu
Hello everyone,

in listing2-2 I've commented out two lines of code, since I thought, there is nothing happening in these registers:

Code: Select all

Extract from asmMain:
...
lea		rcx, fmtStr1
mov		edx, leftOp
mov		r8d, rightOp1
mov		r9d, edx
and		r9d, r8d
call 		printf

;lea 		rex, fmtStr1
;mov		edx, leftOp
mov		r8d, rightOp2
mov		r9d, r8d
and		r9d, edx
call printf
...
But the result is the following:
calling listing2-2:
f0f0f0f AND f0f0f0f0 = 0
<I can't show this character, but it looks like an "L" written with two lines>aH#%f0f0f0f OR f0f0f0f0 = 0
...
When I remove the semicolons, the result is as shown in the book. I thought the register rcx would be untouched, until the address of fmtStr2 is loaded into it, but I must be missing something. Why do the two registers rcx and edx have to be reloaded?

Thank you very much in advance!

Best regards,
sahu

Re: What happens with rxc and edx registers during procedure execution? (listing2-2)

Posted: Mon Jan 27, 2025 11:04 pm
by rhyde
printf uses the Intel/Windows ABI, where register RCX and RDX (among many others) are volatile and can be overwritten by the code being called. That's why you had to reload these registers -- printf is overwriting their values (true for R8 and R9, too).