【发布时间】:2014-02-05 21:16:34
【问题描述】:
我是汇编编程 (x86) 的新手,无法弄清楚我的程序哪里出错了。在我重新显示移动到数组中的值之后,我想显示当前的“SUM”。我认为通过使用“ebx”寄存器,因为除了 Loop2 之外,它在程序中的其他任何地方都没有使用,因此该值不会被覆盖,因此每个“添加”语句都会将新的数组位置值添加到我的“SUM”中.
谁能发现我做错了什么?
INCLUDE Irvine32.inc
COUNT = 3
.data
inputMsg BYTE "Input an integer: ", 0
outputMsg BYTE "Redisplaying the integers: ", 0dh, 0ah, 0
sumMsg BYTE " Sum is now: ", 0
strArray SDWORD COUNT DUP(?)
.code
main PROC
; Read Integers from User
mov ebx, 0
mov ecx, COUNT
mov edx, OFFSET inputMsg
mov esi, OFFSET strArray
L1: call WriteString ; Display Prompt
call ReadInt ; Read input from user
mov [esi], eax ; Store value into array
add esi, TYPE strArray ; Move to next array position
loop L1
call Crlf
; Redisplay the integers
mov edx, OFFSET outputMsg ; Display 'outputMsg'
call WriteString
mov ecx, COUNT
mov esi, OFFSET strArray
L2: mov ebx, 0 ; Initialize ebx to 0
mov eax, [esi] ; Get integer from array
call WriteInt ; Display integer
mov edx, OFFSET sumMsg ; Display value of 'sumMsg'
call WriteString
; mov eax, ebx
add ebx, [esi]
mov eax, ebx ; <---- MOVED from above add ebx, [esi]
call WriteInt
call Crlf
add esi, TYPE strArray ; Move to next array position
loop L2
exit
main ENDP
END main
【问题讨论】:
标签: assembly x86 masm irvine32