I'm very new to assembly and NASM and there is a code:
SECTION .data
array db 89, 10, 67, 1, 4, 27, 12, 34, 86, 3
wordvar dw 123
SECTION .text
global main
main:
mov eax, [wordvar]
mov ebx, [array+1]
mov ebx,0
mov eax,1
int 0x80
Then I run the executable through GDB eax register is set to value 123 as intended, but in ebx there is some mess instead of the array elements value.
Best Answer
Since you're loading 32-bit values from memory, you should declare
array
andwordvar
usingdd
rather thandb
/dw
so that each entry gets four bytes:Also, the indexing in the following is wrong:
You probably meant: