I am learning asm x64, more precisely I currently learn to use data structures. My book tell me that I must use a subregister (aka partial register) to store data from the structure to rdi, but It doesn't explain why.
Could someone please enlighten me?
I tried this piece of code without success (Which was expected):
MOV rdi, [my_struc+my_field]
This code worked as expected:
XOR rbx, rbx
MOV bx, [my_struc+my_field]
MOV rdi, rbx
After reading comments, thank you so much @Jester, I understand better now.
Here is my data structure:
section .bss
STRUC sockaddr_in
sin_family: RESW 1 ; 1*2 bytes
sin_port: RESW 1 ; 1*2 bytes
sin_address: RESD 1 ; 1*4 bytes
sin_zero: RESD 2 ; 2*4 bytes
ENDSTRUC
section .data
sa: ISTRUC sockaddr_in
AT sin_family, DW 0x02 ; AF_INET, see "man socket"
AT sin_port, DW 0x5C11 ; 4444 Little Endian
AT sin_address, DD 0x0100007f ; 127.0.0.1 Little Endian
AT sin_zero, DD 0x0
IEND
I thought that MOV would zero extend automatically, but It seems that actually not.