Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

why using 8 byte register to carry 8 byte type but not using 4 byte register for 4 byte type

This is the code snippet that i am looking

#include <cstdint>
int main() {

    unsigned int i = 0x11111111;
    unsigned int j = 0xFFFFFFFF;

    uint64_t k = 0xFFFFFFFF11111111;
}
0000000140001000  sub         rsp,18h  
0000000140001004  mov         dword ptr [rsp],11111111h  
000000014000100B  mov         dword ptr [rsp+4],0FFFFFFFFh  
0000000140001013  mov         rax,0FFFFFFFF11111111h  
000000014000101D  mov         qword ptr [rsp+8],rax  
0000000140001022  xor         eax,eax  
0000000140001024  add         rsp,18h  
0000000140001028  ret

We are using rax register to carry uint64_t value.

Why we are not using eax or some other 32 bit register for int?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Since you’re not compiling with optimization, it is not using registers to hold any of your variables — they’re all in the stack frame (at rsp, rsp+4,and rsp+8)

rax here is just used here to temporarily hold the constant 0xFFFFFFFF11111111 as there’s no single instruction to write a 64 bit value to memory. There is an instruction to write a 32-bit value to memory, so that is used for the unsigned int initializations

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading