【发布时间】:2026-02-07 21:05:01
【问题描述】:
我无法理解为什么我的 cmp 语句无法正常工作。
当我运行它时,我首先输入 0,然后它转到 storeValue。我在第二个值中输入 0,它会像预期的那样进入 searchArray。
我的 cmp 和 jump 语句上有断点,并且在 AL 上有一个监视,所以我不明白为什么它应该在此时提示输入搜索值时存储第一个 0。
感谢收看。
.DATA
prompt1 BYTE "Enter a value to put in array or 0 to search array.", 0
prompt2 BYTE "Enter a value to search array for.",0
intArray DWORD ?
numElem DWORD 0
SearchVal DWORD ?
resultNope BYTE "Not in array.",0
.CODE
_MainProc PROC
lea ebx, intArray ;get the address of array.
start: input prompt1, intArray, 50 ;read in integer
atod intArray ;convert to int
mov al, [ebx] ;move int to register
cmp al, 0 ;if integer is positive - store it!
jg storeValue ;JUMP!
cmp al, 0 ;if 0 - time to search array!
je searchArray ;JUMP!
storeValue: add numElem, 1 ;Adds 1 to num of elements in array.
mov [ebx], al ;moves number into array.
add ebx, 1 ;increment to next array address.
jmp start ;get next number for array. JUMP!
searchArray:input prompt2, searchVal, 50 ;What are we searching array for?
atod searchVal ;convert to int
lea ebx, intArray ;get address of array.
mov ecx, 1 ;set loop counter to 1.
【问题讨论】: