I have a 64 bit register which holds a memory address. If I perform an arithmetic operation on the lower half of the register and then try to dereference it, I get a segmentation fault. Here is an example:
movsx rax, BYTE PTR [rdi] # ok
add edi, 1 # the address is correct but....
movsx rax, BYTE PTR [rdi] # segmentation fault here
If I change edi to rdi in line 2 it works, so I am just wondering why I can’t use the lower half of rdi in this case. I would also appreciate it if anyone has any links/references with information about the proper use of the lower parts of registers.
Thanks a lot for your help.
When you do operations on a
edior any other 32-bit bottom-half register, it automatically zeros the top half of the whole register.Therefore the upper 32-bits of
rdiwill be zero after theadd edi, 1.