I have a question regarding the subsections of the 32-bit registers in x86 assembly: Are the lower subsections of a register (when used) treated like a part of the corresponding 32-bit register?
ror cl,2 ror cl,2 push ecx pop eax
Take for example the code section above - since CL
is a subsection of the ECX
register, when I push the contents of the register onto the stack does what was in the CL
subsection get pushed onto the stack as well? Or are they treated separately?
And suppose if I then popped the stack onto the EAX
register does what was in the CL
register from before go into the EAX
register?
The ECX
register contains CX
in its lower part, which contains CH
and CL
as represented in the picture below. When modifying the value stored in CL
, you also change CX
and ECX
, but not CH
.
To answer your questions:
Q: When I push the contents of the register [ECX
] onto the stack does what was in the CL
subsection get pushed onto the stack as well? Or are they treated seperatley?.
A: All in one shot. CL
is part of ECX
. CL
is just a way provided by the processor to access a part of ECX
.
Q: And suppose if I then poped the stack onto the EAX
register does what was in the CL
register from before go into the EAX
register?.
A: Yes. More precisely, what was in CL
would go into AL
.
Source: A tutorial on Register Allocation by Puzzle Solving (on compilers.cs.ucla.edu)