My program accepts 4 integers and is suppose to display them back to the user. When printing the values I don't get the expected results. I'm using MASM with Kip's Irvine32 library
My code is:
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
A sample run of my program:
Enter a number
1
2
3
4
4
4
4
4
After entering the numbers 1,2,3, and 4 the program should have displayed those numbers back to the user. The output I expected is:
Enter a number
1
2
3
4
1
2
3
4
If I modify the loop that prints the numbers so that I place the value to print in EAX instead of EBX with this code:
mov eax,arr[ecx]
call writedec
I end up with nonsensical output values like this:
Enter a number
1
2
3
4
67305985
262914
1027
4
Why is my program behaving this way, and how can I modify it to get the expected results?