I'm trying to work with arrays in GNU assembly. In my opinion the following code must exit with value 3. But it exits with 13.
.section __DATA,__data
inArr:
.word 13, 2, 3, 4, 5, 6, 7, 8, 9, 10
outArr:
.fill 10, 2
.section __TEXT,__text
.globl _main
_main:
movq $3, %rcx
movw inArr(%rip, %rcx, 2), %di # load *((rcx * 2)+ rip + &inArray) into %di, isn't it?
movl $0x2000001, %eax # exit
syscall
In my opinion movw inArr(%rip, %rcx, 2), %di command is equivalent to something like %di = inArr[%rcx]. Unfortunately I can't find any examples with array in GAS.
What's wrong with that code? And how shall I address n-th element of array?