在Assembly x86 NASM中从内存读取16位数据
我正在尝试在汇编中做一个非常简单的练习:位于连续存储单元中的总和N个数字。 这是我的实际代码:
global _start
section .data
array: DD 300,10,20,30,40,50 ; Allocate the numbers
arrayLen: EQU $-array ; Get the quantity of numbers
section .text
_start:
mov ecx, 0 ; The counter
mov ebx, 0 ; The Accumulator
loop: add ebx, DWORD [array+ecx] ; get the i-th word and add it to the accumulator
add ecx, 4
cmp ecx, arrayLen
jne loop
mov eax, 1
int 0x80
程序编译并正确执行,但返回的值不正确。 结果应该是450,而我得到194。
我注意到194是与450相同的比特流,但是第9位被省略了。 调试我的程序我争辩说,出于某种原因,当我阅读时我无法理解
[array+ecx]
虽然我指定了关键字DWORD,但它只读取8位数据。
有人能帮我吗? 提前致谢
该程序正确地总结了阵列。 问题是返回结果。
[更正,谢谢Jester。]
您将返回值传递给sys_exit() (这是mov eax, 1; int 0x80作用)。 sys_exit()仅保留返回值的低8位(其他位用于某些标志)。
这是第九位丢失的地方。
Shell观察已经截断的返回值并将其打印出来。
链接地址: http://www.djcxy.com/p/72451.html