I'm new to writing posts with code imbedded in them so give me a break if this looks terrible, or suggestions on how to make it look nicer. :)
The issue I'm having is pretty much what the title says. I am making a simple calculator for an assignment, I am trying to have the program compare an inputted math operation such as ( ,-,*,/).
*Then have a cmp set up something like....
cmp MathOper, 43...*
*But I am having troubles getting the program to recognize the right thing. I'll post a copy of the code below, but keep in mind this is a rough draft just trying to work out some ideas. *
Thanks for any and all help!
; 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
CodePudding user response:
You don't want to call atod on string
after reading the input, because it isn't a number.
Just copy the first character of the string into MathOper using this:
movzx eax, [string]
mov MathOper, eax