What is the proper way to access array elements in x86_64? For example, here is what I have going so far:
my_array: .word 20,25,30,35
.globl _start
_start:
movq $0, %rdi # should we use rdi for the offset?
movz my_array(,%rdi,2), $r13 # how to move two bytes in r13 and zero-pad the rest?
add $6, %rdi # move to next index position for my_array[3]
movz my_array(,%rdi,2), $r14 # how to move two bytes in r14 and zero-pad the rest?
Basically what I'm trying to do is the following in pseudocode:
%r13 = my_array[0] # (20)
%r14 = my_array[3] # (35)
This is pretty sloppy and I'm sure the wrong way to do it (not to mention the movz
is mis-sized and I'm having trouble figuring that out. What would be the correct way to do this then, using indexed-addressing mode?