我不知道为什么这个程序无法输出
1 +2 +3 4
输出
4214784 1967600538 2130567168 1638356
我想这是地址,但为什么呢?如何纠正?
这是我的代码:
include irvine32.inc
.data
matrix dword 1, 2, 3, 4
.code
print proto, m:ptr dword
main proc
invoke print, addr matrix
exit
main endp
print proc, m:ptr dword
mov eax, m[0 * type m]
call writeint
mov eax, m[1 * type m]
call writeint
mov eax, m[2 * type m]
call writeint
mov eax, m[3 * type m]
call writeint
ret
print endp
end main
感谢您的回答<(__)>
答案 0 :(得分:0)
m
是在堆栈上传递的指针。汇编程序会将m
转换为[ebp+8]
之类的内容。索引将访问堆栈中的项目,从该位置开始,这不是您想要的。您需要取消引用m
指针,只有将其加载到寄存器中才能执行此操作。
mov ecx, m ; this will be mov ecx, [ebp+8] or similar
mov eax, [ecx + 0*4] ; first item
call WriteInt
mov eax, [ecx + 1*4] ; second item
call WriteInt
...
我不建议初学者使用其汇编程序的精美功能,而不了解准确生成的代码。