尝试将“+”的输入与其 ASCII 值 43 进行比较
Trying to compare input of '+' with its ASCII value of 43
我刚开始编写嵌入了代码的 posts,所以如果这看起来很糟糕,请让我休息一下,或者关于如何让它看起来更好的建议。 :)
我遇到的问题与标题所说的差不多。我正在为作业制作一个简单的计算器,我试图让程序比较输入的数学运算,例如 (+,-,*,/)。
*然后让 cmp 设置类似....
cmp 数学运算,43...*
*但是我无法让程序识别正确的东西。我将 post 以下代码的副本,但请记住,这只是一个草稿,只是试图找出一些想法。 *
感谢您的帮助!
; Author:
; Date: 03/22/2022
.586
.MODEL FLAT
INCLUDE io.h ; header file for input/output
.STACK 4096
.DATA
num1 DWORD ?
num2 DWORD ?
MathOper DWORD ?
result DWORD 20 DUP (?), 0
string BYTE 40 DUP (?), 0
Num1prm BYTE "Enter First Number", 0
Num2prm BYTE "Enter Second Number", 0
MathOPprm BYTE "Enter Math Operation (+,-,*,/)", 0
Resultprm BYTE "The Result is: ", 0
.CODE
_MainProc PROC
loopy:
input Num1prm, string, 20
atod string
mov num1, eax
input MathOPprm, string, 20
atod string
mov MathOper, eax
input Num2prm, string, 20
atod string
mov num2, eax
;HAVING ISSUES GETTING THIS TO WORK
cmp MathOper, 43
jne SUBTRACTION
call Addition
dec ecx
jnz loopy
SUBTRACTION:
cmp MathOper, 45
jne MULTIPLICATION
call Subtraction
MULTIPLICATION:
cmp MathOper, 42
jne DIVISION
call Multiplication
DIVISION:
cmp MathOper, 47
call Division
cmp MathOper, 101
endloopy:
mov eax, 0 ; exit with return code 0
ret
_MainProc ENDP
; end of source code
Addition PROC
push ebp
mov ebp, esp
push ebx
mov eax, num1
mov ebx, num2
add eax, ebx
dtoa result, eax
output Resultprm, result, 40
pop ebx
pop ebp
ret
Addition ENDP
Subtraction PROC
push ebp
mov ebp, esp
push ebx
mov eax, num1
mov ebx, num2
sub eax, ebx
dtoa result, eax
output Resultprm, result, 40
pop ebx
pop ebp
ret
Subtraction ENDP
Multiplication PROC
push ebp
mov ebp, esp
push ebx
mov eax, num1
mov ebx, num2
mul ebx
dtoa result, eax
output Resultprm, result, 40
pop ebx
pop ebp
ret
Multiplication ENDP
Division PROC
push ebp
mov ebp, esp
push ebx
mov eax, num1
mov ebx, num2
cdq
idiv ebx
dtoa result, eax
output Resultprm, result, 40
pop ebx
pop ebp
ret
Division ENDP
END
您不想在读取输入后在 string
上调用 atod,因为它不是数字。
只需使用以下命令将字符串的第一个字符复制到 MathOper 中:
movzx eax, [string]
mov MathOper, eax
我刚开始编写嵌入了代码的 posts,所以如果这看起来很糟糕,请让我休息一下,或者关于如何让它看起来更好的建议。 :)
我遇到的问题与标题所说的差不多。我正在为作业制作一个简单的计算器,我试图让程序比较输入的数学运算,例如 (+,-,*,/)。
*然后让 cmp 设置类似....
cmp 数学运算,43...*
*但是我无法让程序识别正确的东西。我将 post 以下代码的副本,但请记住,这只是一个草稿,只是试图找出一些想法。 *
感谢您的帮助!
; Author:
; Date: 03/22/2022
.586
.MODEL FLAT
INCLUDE io.h ; header file for input/output
.STACK 4096
.DATA
num1 DWORD ?
num2 DWORD ?
MathOper DWORD ?
result DWORD 20 DUP (?), 0
string BYTE 40 DUP (?), 0
Num1prm BYTE "Enter First Number", 0
Num2prm BYTE "Enter Second Number", 0
MathOPprm BYTE "Enter Math Operation (+,-,*,/)", 0
Resultprm BYTE "The Result is: ", 0
.CODE
_MainProc PROC
loopy:
input Num1prm, string, 20
atod string
mov num1, eax
input MathOPprm, string, 20
atod string
mov MathOper, eax
input Num2prm, string, 20
atod string
mov num2, eax
;HAVING ISSUES GETTING THIS TO WORK
cmp MathOper, 43
jne SUBTRACTION
call Addition
dec ecx
jnz loopy
SUBTRACTION:
cmp MathOper, 45
jne MULTIPLICATION
call Subtraction
MULTIPLICATION:
cmp MathOper, 42
jne DIVISION
call Multiplication
DIVISION:
cmp MathOper, 47
call Division
cmp MathOper, 101
endloopy:
mov eax, 0 ; exit with return code 0
ret
_MainProc ENDP
; end of source code
Addition PROC
push ebp
mov ebp, esp
push ebx
mov eax, num1
mov ebx, num2
add eax, ebx
dtoa result, eax
output Resultprm, result, 40
pop ebx
pop ebp
ret
Addition ENDP
Subtraction PROC
push ebp
mov ebp, esp
push ebx
mov eax, num1
mov ebx, num2
sub eax, ebx
dtoa result, eax
output Resultprm, result, 40
pop ebx
pop ebp
ret
Subtraction ENDP
Multiplication PROC
push ebp
mov ebp, esp
push ebx
mov eax, num1
mov ebx, num2
mul ebx
dtoa result, eax
output Resultprm, result, 40
pop ebx
pop ebp
ret
Multiplication ENDP
Division PROC
push ebp
mov ebp, esp
push ebx
mov eax, num1
mov ebx, num2
cdq
idiv ebx
dtoa result, eax
output Resultprm, result, 40
pop ebx
pop ebp
ret
Division ENDP
END
您不想在读取输入后在 string
上调用 atod,因为它不是数字。
只需使用以下命令将字符串的第一个字符复制到 MathOper 中:
movzx eax, [string]
mov MathOper, eax