【发布时间】:2017-08-28 20:11:19
【问题描述】:
我的代码从用户那里得到两个输入并将它们相乘。正如你在下面看到的。
我试图将事情拆分为单独的程序,然后在最后调用它们。
我确实对我所做的事情有一些疑问。在每个 getValue 过程的第一次比较之后,我明白我需要跳转到下一个比较,但是在第二次比较之后,我不知道该跳转到哪里。
在第二个比较之后跳转到下一个过程的开始是否有意义,或者我应该直接跳到返回或结束过程语句?
我还想就是否只使用一个 getValue 过程然后在最后调用它两次而不是调用两个单独的过程来做同样的事情是否有意义。
它说它构建成功,但是当我运行它时,它只是说“按任意按钮继续......”而不是提供代码,所以我不知道这是怎么回事。
INCLUDE Irvine32.inc
.data
intVal1 SDWORD ? ; User input one
intVal2 SDWORD ? ; User input two
prompt BYTE "The result of multiplying the numbers is ",0
prompt2 BYTE "Enter a number that will be multiplied",0
prompt3 BYTE "Error. Number not in range.",0
.code
; Error procedure displays error prompt
error PROC
mov edx, OFFSET prompt3
call WriteString
ret
error ENDP
; GetValue1 procedure will get first input from user and display error and end program when input not in range
GetValue1 PROC
mov edx, OFFSET prompt2
call WriteString ; tells the user to enter a number
call ReadInt
mov intVal1,eax ; save the returned value from eax to intVal1
cmp intVal1, 32767
jl Loop1 ; if intVal1 is less than 32767 jump to Loop1, otherwise continue with error procedure
call error
jmp end
Loop1: cmp intVal1, -32768
jg Loop2 ; if intVal1 is greater than -32768 jump to Loop2, otherwise continue with error procedure
call error
jmp end
ret
GetValue1 ENDP
; GetValue2 procedure will do the same thing as GetValue1
GetValue2 PROC
Loop2: mov edx, OFFSET prompt2
call WriteString
call ReadInt
mov intVal2,eax
cmp intVal1, 32767
jl Loop3 ; if intVal1 is less than 32767 jump to Loop3, otherwise continue with error procedure
call error
jmp end
Loop3: cmp intVal1, -32768
jg Loop4 ; if intVal1 is greater than -32768 jump to Loop4, otherwise continue with error procedure
call error
jmp end
ret
GetValue2 ENDP
; MultiplyAndDisplay will multiply the inputs and display the result along with a prompt
MultiplyAndDisplay PROC
Loop4: imul eax, intVal1 ; signed multiply of eax by intVal1
mov edx, OFFSET prompt
call WriteString ; Writes the prompt in edx
call WriteDec ; Writes the value in eax
ret
MultiplyAndDisplay ENDP
main PROC
call GetValue1
call GetValue2
call MultiplyAndDisplay
exit
main ENDP
END main
【问题讨论】:
-
编辑删除了未向问题添加任何细节的句子。添加了段落分隔符以提高可读性。
标签: visual-studio-2010 assembly masm irvine32 procedures