【发布时间】:2015-11-11 10:45:31
【问题描述】:
我的程序接受 4 个整数,并假设将它们显示给用户。打印值时,我没有得到预期的结果。我正在使用 MASM 和 Kip 的 Irvine32 library
我的代码是:
include irvine32.inc
.data
msg byte "Enter a number",0
arr dword 4 dup(?)
len=($-arr)/4
.code
main PROC
mov edx,offset msg
call writestring
call crlf
mov eax,0
mov ecx,0
.while(ecx<len)
call readdec
mov arr[ecx],eax
inc ecx
.endw
mov ebx,0
mov ecx,0
.while(ecx<len)
mov ebx,arr[ecx]
call writedec
call crlf
inc ecx
.endw
exit
main ENDP
END main
我的程序的示例运行:
Enter a number
1
2
3
4
4
4
4
4
在输入数字 1、2、3 和 4 后,程序应该将这些数字显示给用户。我期望的输出是:
Enter a number
1
2
3
4
1
2
3
4
如果我修改打印数字的循环,以便使用以下代码将要打印的值放在 EAX 而不是 EBX 中:
mov eax,arr[ecx]
call writedec
我最终得到如下无意义的输出值:
Enter a number
1
2
3
4
67305985
262914
1027
4
为什么我的程序会这样,我该如何修改它以获得预期的结果?
【问题讨论】:
-
是什么让您认为
writedec期望在ebx中输入? -
@Micheal 我在第二个循环中使用了 eax,但它打印了一些非常长的值。所以我改用了ebx。
标签: arrays assembly x86 masm irvine32