我正在尝试完成MASM计划。这是我的目标(我的作业)。
修改第5.6.1节(第173-175页)中的求和程序,如下所示:使用常量选择数组大小:
ARRAY_SIZE = 20
数组DWORD ARRAY_SIZE DUP(?)
编写一个新过程,提示用户输入要处理的整数数。将它传递给PromptForIntegers过程。例如,
将添加多少个整数? 5
INCLUDE Irvine32.inc
array_size = 10
.data
prompt1 byte "How many integers will be added?", 0
prompt2 byte "Enter a signed integer: ", 0
prompt3 byte "The sum of the integers is: ", 0
array dword array_size dup(?)
.code
main proc
call clrscr
mov ecx,eax
call promptMes
call arraysum
call displaysum
exit
main endp
promptMes proc uses ecx edx esi
mov edx,offset prompt1
mov esi,offset array
call writestring
call readint
call crlf
call promptforintegers
ret
promptMes endp
promptforintegers proc uses ecx edx esi
mov edx,offset prompt2
l1: call writestring
call readint
call crlf
mov [esi], ax
add esi,type word
loop l1
ret
promptforintegers endp
arraysum proc uses esi ecx
mov eax, 0
l1: add eax,[esi]
add esi,type dword
loop l1
ret
arraysum endp
mov edx, offset prompt3
call writestring
call writeint
call crlf
ret
displaysum endp
end main
我的问题是我的计数器继续无限次迭代,我的问题是我如何以及在何处获取上面的用户输入(5)并将计数器和(5)传递给过程promptForIntegers?
我在网上看到same question,这是他们得到的回复。
函数readint在哪里?
如何将ecx设置为用户想要的整数数量?也许 它在readint中设置了吗?
但是,他们没有显示代码的来源完整。我不知道如何使用readint修改我的代码。任何人都可以告诉我这与readint函数的相似之处吗?
答案 0 :(得分:-1)
INCLUDE Irvine32.inc
array_size = 10
.data
prompt1 byte "How many integers will be added?", 0
prompt2 byte "Enter a signed integer: ", 0
prompt3 byte "The sum of the integers is: ", 0
array dword array_size dup(?)
.code
main proc
call clrscr
mov ecx,eax
call promptMes
call arraysum
call displaysum
exit
main endp
promptMes proc uses ecx edx esi
mov edx,offset prompt1
mov esi,offset array
call writestring
call readint
call crlf
call promptforintegers
ret
promptMes endp
promptforintegers proc uses ecx edx esi
mov edx,offset prompt2
l1: call writestring
call readint
call crlf
mov [esi], ax
add esi,type word
loop l1
ret
promptforintegers endp
arraysum proc uses esi ecx
mov eax, 0
l1: add eax,[esi]
add esi,type dword
loop l1
ret
arraysum endp
mov edx, offset prompt3
call writestring
call writeint
call crlf
ret
displaysum endp
end main