.
386
include irvine32.inc
.model small
.stack 100h
.data
charMsg DB "Enter Your choice (y/n):- ",0 ; Prompt to ask if user wants to
continue
char DB ?
charInv DB "Invalid! Enter character again:- ",0 ; Message for invalid
character input
exitProg DB "Program exit successfully!", 0 ; Exit message
num1Msg DB "Enter 1st number:- ",0 ; first number
num2Msg DB "Enter 2nd number:- ",0 ; second number
n1 DD ?
n2 DD ?
num1Inv DB "Number 1 is invalid! Enter again:- ",0 ; invalid first number
num2Inv DB "Number 2 is invalid! Enter again:- ",0 ; invalid second number
opMsg DB "Enter arithmetic operator:- ",0 ; operator input
op DB ?
opInv DB "Invalid operator! Enter again", 0 ; invalid operator input
SUM_ DB "Addition is :- ", 0 ; addition result
SUB_ DB "Subtraction is :- ", 0 ; subtraction result
MUL_ DB "Multiplication is :- ", 0 ; multiplication result
DIV_ DB "Division is :- ", 0 ; division result
REM_ DB "Remainder is :- ", 0 ; remainder result
.code
main proc
start:
mov edx, offset charMsg
call writestring ;user choice
call readchar
call writechar
call crlf
cmp al, 'y' ; Check if input is 'y'
je takeInputs
cmp al, 'Y' ; Check if input is 'Y'
je takeInputs
cmp al, 'n' ; Check if input is 'n'
jne programExit
cmp al, 'N' ; Check if input is 'N'
jne programExit
jmp invalidChar ; Jump to invalid character handler
takeInputs:
num1:
mov edx, offset num1Msg
call writestring ; Prompt for first number
call readint
cmp eax, 1 ; Validate number (must be >= 1)
jl num1Error
mov n1, eax
num2:
mov edx, offset num2Msg
call writestring ; Prompt for second number
call readint
cmp eax, 1 ; Validate number (must be >= 1)
jl num2Error
mov n2, eax
movOPMSG:
mov edx, offset opMsg
call writestring ; Prompt for arithmetic operator
call readchar
call writechar
call crlf
cmp al, '+' ; Check addition operator
je ADDITION
cmp al, '-' ; Check subtraction operator
je SUBTRACTION
cmp al, '*' ; Check multiplication operator
je MULTIPLICATION
cmp al, '/' ; Check division operator
je DIVISION
cmp al, '%' ; Check remainder operator
je REMAINDER
jmp invalidOp ; Handle invalid operator input
ADDITION:
mov eax, n1
add eax, n2 ; Perform addition
mov edx, offset SUM_
call writestring
call writeint
call crlf
jmp start ; Loop back to start
SUBTRACTION:
mov eax, n1
sub eax, n2 ; Perform subtraction
mov edx, offset SUB_
call writestring
call writeint
call crlf
jmp start
MULTIPLICATION:
mov eax, n1
mul n2 ; Perform multiplication
mov edx, offset MUL_
call writestring
call writeint
call crlf
jmp start
DIVISION:
mov edx, 0
mov eax, n1
div n2 ; Perform division
mov edx, offset DIV_
call writestring
call writeint
call crlf
jmp start
REMAINDER:
mov edx, 0
mov eax, n1
div n2 ; Perform division to get remainder
mov eax, edx
mov edx, offset REM_
call writestring
call writeint
call crlf
jmp start
invalidOp:
mov edx, offset opInv
call writestring ; Display invalid operator message
jmp movOPMSG
num1Error:
mov edx, offset num1Inv
call writestring ; Display invalid number 1 message
call crlf
jmp num1
num2Error:
mov edx, offset num2Inv
call writestring ; Display invalid number 2 message
call crlf
jmp num2
invalidChar:
mov edx, offset charInv
call writestring ; Display invalid character message
call crlf
jmp start
programExit:
mov edx, offset exitProg
call writestring ; Display exit message
invoke ExitProcess, 0 ; Exit program
main endp
end main