Assignment: Calculator Description: addition (+), subtraction (-), multiplicatio
ID: 3891125 • Letter: A
Question
Assignment: Calculator Description: addition (+), subtraction (-), multiplication (*), integer division (/), modulo division (%), and Write a calculator program in assembly. It should handle the following functions exponentiation (). Your program should.. 1. Read an integer from the user. 2. Read a character from the user, representing the function. (+,-, *, /, %, ^) 3. Read another integer from the user 4. Print an equals sign 5. Print the result. Please comment your code, and format it so that it looks clean! (examples on next page)Explanation / Answer
.data
line byte "Welcome to simple calculator in Assembly",0,13h,10h
line1 byte "Choose any one operation : '+' '-' '/' '*' '%' ",0,13h,10h
message1 byte "Enter first Integer: ",0,13h,10h
message2 byte "Enter second integer: ",0,13h,10h
put1 byte "Result is equal to =",0
put2 byte "First no: ",0
put3 byte "Second no: ",0
num1 word?
num2 word?
button byte?
.code
main PROC
call clrscr
mov edx,offset line
call write string
call calf
start:
mov edx,offset msg1 ;Read 1st num
call writestring
call readint
mov num1,ax
call crlf
mov edx,offset line1
call writestring
mov edx,offset button
call readchar
mov button,al
mov edx,offset msg2 ;Read 2nd num
call writestring
call readint
mov num2,ax
cmp button,'+'
JE addition
cmp button,'-'
JE subtraction
cmp button,'*'
JE multiplication
cmp button,'/'
JE division
cmp button,'%'
JE modulus
addition:
mov edx,offset put2 ;display both numbers
call writestring
mov ax,num1
call writeint
call crlf
mov edx,offset put3
call writestring
mov ax,num2
call writeint
call crlf
call crlf
mov edx,offset put1
call writestring
mov ax,num1
add ax,num2
call writeint
call crlf
JMP start
subtraction:
mov edx,offset put2 ;display both numbers
call writestring
mov ax,num1
call writeint
call crlf
mov edx,offset put3
call writestring
mov ax,num2
call writeint
call crlf
call crlf
mov edx,offset put1
call writestring
mov ax,num2
sub ax,num1
call writeint
call crlf
JMP start
multiplication:
mov edx,offset put2 ;display both numbers
call writestring
mov ax,num1
call writeint
call crlf
mov edx,offset put3
call writestring
mov ax,num2
call writeint
call crlf
call crlf
mov edx,offset put1
call writestring
mov ax,num1
mov bx,num2
mul bx
call writeint
call crlf
JMP start
division:
mov edx,offset put2 ;display both numbers
call writestring
mov ax,num1
call writeint
call crlf
mov edx,offset put3
call writestring
mov ax,num2
call writeint
call crlf
call crlf
mov edx,offset put1
call writestring
mov ax,num1
mov bx,num2
mov dx,0
div bx
call writeint
call crlf
JMP start
modulus:
mov edx,offset put2 ;display both numbers
call writestring
mov ax,num1
call writeint
call crlf
mov edx,offset put3
call writestring
mov ax,num2
call writeint
call crlf
call crlf
mov edx,offset put1
call writestring
mov ax,num1
mov bx,num2
mov dx,0
div dx
mov remainder, dx
call writeint
call crlf
JMP start
stop:
exit main end
end main
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.