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

Support for Randall Hyde's "The Art of 64-Bit Assembly" book
Post Reply
sahu
Posts: 1
Joined: Sat Jan 04, 2025 9:04 am

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

Post 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
rhyde
Site Admin
Posts: 53
Joined: Sun Dec 04, 2022 5:36 pm

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

Post 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).
Post Reply