I am new to assembly and trying to do a small excersise for the classroom.
Collecting 3 input variables from user:
- 1st one is a math operation symbol ( + - and *)
- 2nd variable is a number to add or substract from other number (3rd variable)
example 1: User should input in-order: +, 4, and 5 and gets 9
example 2: user types -, 9, 5 should get 4
I'm not able to compare the math operator as a string, so it is being stuck at the addition problem.. it only adds the numbers even if changed the symbol to minus.
tried changing the GET_STRING to GET_DEC and made numbers act as math symbols, it worked, so I think it is a syntax issue I'm not able to figure out how to check/validate the GET_STRING input or how to compare it exactly with the logic
I am using simple sasm IDE/editor
Here is my code appreciate your help in advance
%include "io.inc"
section .data
section .text
global CMAIN
CMAIN:
mov ebp, esp; for correct debugging
GET_STRING [operation],8 // here I treid everything, even GET_CHAR didn't work
GET_DEC 4,[firstVar]
GET_DEC 4,[secondVar]
mov eax,[operation]
cmp eax, opAdd
je Addit
jne L2
L2:
mov eax,[operation]
cmp eax, opSub
je Subbit
jne L3
L3:
mov eax,[operation]
cmp eax, "*"
je Multit
Addit:
mov eax,[firstVar]
mov ebx,[secondVar]
add eax,ebx
jmp PRINT
Subbit:
mov eax,[firstVar]
mov ebx,[secondVar]
sub eax,ebx
jmp PRINT
Multit:
mov eax,[firstVar]
mov ebx,[secondVar]
mul ebx
jmp PRINT
PRINT:
PRINT_DEC 4,eax
xor eax, eax
ret