在nasm中处理数组元素 [英] addressing array elements in nasm
本文介绍了在nasm中处理数组元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对汇编和NASM还是很陌生,有一个代码:
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
然后我通过GDB eax寄存器运行可执行文件,并按预期将其设置为值123,但是在ebx中,有些混乱而不是数组元素的值.
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.
推荐答案
由于要从内存中加载32位值,因此应使用dd
而不是db
/dw
,以便每个条目获得四个字节:
Since you're loading 32-bit values from memory, you should declare array
and wordvar
using dd
rather than db
/dw
so that each entry gets four bytes:
array dd 89, 10, 67, 1, 4, 27, 12, 34, 86, 3
wordvar dd 123
此外,以下索引是错误的:
Also, the indexing in the following is wrong:
mov ebx, [array+1]
您可能是说:
mov ebx, [array+1*4]
这篇关于在nasm中处理数组元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文