过程ReadVal应该循环并要求用户输入10个整数(AS STRINGS),最终将每个整数存储在一个数组中。 ReadVal使用宏getString,它第一次工作。然后其他9次打印“请输入无符号整数:”但不停止允许用户输入值。因此,它肯定会调用宏,但为什么它不会停止并等待接下来的9次输入。
INCLUDE Irvine32.inc
LEN = 10 ; Number of elements in array.
getString MACRO buffer, size
push eax
push ecx
push edx
mov edx, OFFSET userMsg_2
call WriteString
mov edx, buffer ; buffer passed by reference, so no OFFSET req'd.
mov eax, size
mov ecx, [eax] ; Dereference sizeElem to ecx counter.
call ReadString
pop edx
pop ecx
pop eax
ENDM
.data
userMsg_2 BYTE "Please enter an unsigned number: ",0
array DWORD LEN dup(?)
arLength DWORD LEN
sizeElem BYTE 11 ; Number of digits allowed in. reading ints as strings.
holder DWORD ? ; Temp memory location for storing string input/output.
.code
main PROC
push OFFSET array
push OFFSET arLength
push OFFSET sizeElem
push OFFSET holder
call ReadVal
exit
main ENDP
ReadVal PROC
push ebp
mov ebp, esp
push ecx
mov esi, [ebp+20] ; esi has starting address of array.
mov eax, [ebp+16] ; @arLength
mov ecx, [eax] ; ecx gets arLength.
cmp ecx, 0
je L2
L1:
getString [ebp+8], [ebp+12] ; [ebp+8] gets the user inputted string.
mov esi, [ebp+8] ; mov string in holder into array[esi].
add esi, TYPE DWORD
loop L1
L2:
pop ecx
pop ebp
ret 16
ReadVal ENDP
END main
答案 0 :(得分:3)
我认为问题是ReadString期望ECX中的值是DWORD。将它作为BYTE给出一个数字令人困惑。将sizeElem声明为DWORD可以解决问题。
您可能希望将持有者声明为使用BYTE而不是DWORD,我认为这更常见于字符串存储。