Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This program is assembly language and must ask the user for 2 numbers from 0 to 9, then it should ask the user if it

This program is assembly language and must ask the user for 2 numbers from 0 to 9, then it should ask the user if it wants to either add, subtract, divide or multiply these 2 numbers. Then calculate accordingly and display the result. When the user inputs the arithmetic operation it should be its respective symbol. The code doesn't work please fix.

.MODEL SMALL

.STACK

.DATA

STRING db "Enter a digit: ",13,10,13,10,'$' ADDITION db "The sum is: ",13,10,13,10,'$' MULTIPLICATION db "The product is: ",13,10,13,10,'$' DIVISION db "The quotient is: ",13,10,13,10,'$' SUBTRACTION db "The difference is: ",13,10,13,10,'$' DIGIT1 db ? DIGIT2 db ? RESULT db ?

.CODE MAIN PROC MOV AX, @DATA MOV DS, AX

call SHOW_STRING

call READ_DIGIT mov DIGIT1, al

call SHOW_STRING

call READ_DIGIT mov DIGIT2, al

call ADD_DIGITS mov dx, offset ADDITION call SHOW_STRING call ADD_ASCII

call MULTIPLY_DIGITS mov dx, offset MULTIPLICATION call SHOW_STRING call ADD_ASCII

call DIVIDE_DIGITS mov dx, offset DIVISION call SHOW_STRING call ADD_ASCII

call SUBTRACT_DIGITS mov dx, offset SUBTRACTION call SHOW_STRING call ADD_ASCII

MOV AX, 4C00h INT 21h MAIN ENDP

;***********************************************************************************

SHOW_STRING PROC mov dx, offset STRING ; write all characters mov ah, 9 ; in the standard output int 21h ; DX has the offset of the first character RET ; the last character must be '$' SHOW_STRING ENDP

;***********************************************************************************

ADD_ASCII PROC mov dl, RESULT add dl, 48 call WRITE_CHARACTER RET ADD_ASCII ENDP

;***********************************************************************************

WRITE_CHARACTER PROC mov ah, 2h ; write a character to standard output mov dl, al ; DL has the character int 21H RET WRITE_CHARACTER ENDP

;***********************************************************************************

READ_DIGIT PROC mov ah, 1h ; read a character from standard input int 21h ; AL stores the character read ; check if the character is a digit cmp al, '0' jl INVALID cmp al, '9' jg INVALID sub al, 30h ; convert from ASCII to binary digit ret

INVALID: ; handle invalid input mov al, '0' ret READ_DIGIT ENDP

;***********************************************************************************

ADD_DIGITS PROC mov al, DIGIT1 add al, DIGIT2 mov RESULT, al RET ADD_DIGITS ENDP

;***********************************************************************************

MULTIPLY_DIGITS PROC mov al, DIGIT1 mul DIGIT2 mov RESULT, al RET MULTIPLY_DIGITS ENDP

;***********************************************************************************

DIVIDE_DIGITS PROC mov al, byte ptr [DIGIT1] mov bl, byte ptr [DIGIT2] xor ah, ah ; clear upper half of AX cmp bl, 0 jz division_by_zero div bl jmp division_done division_by_zero: mov al, 0 division_done: mov byte ptr [RESULT], al RET DIVIDE_DIGITS ENDP

;***********************************************************************************

SUBTRACT_DIGITS PROC mov al, DIGIT1 sub al, DIGIT2 mov RESULT, al RET SUBTRACT_DIGITS ENDP

;***********************************************************************************

SHOW_RESULT PROC mov dx, offset RESULT mov ah, 9 int 21h mov dx, offset ADDITION mov ah, 9 int 21h RET SHOW_RESULT ENDP

;**********************************************************************************

END_PROGRAM PROC mov ax, 4C00h ; terminate the program int 21h END_PROGRAM ENDP

;***********************************************************************************

end MAIN

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Next Generation Databases NoSQLand Big Data

Authors: Guy Harrison

1st Edition

1484213300, 978-1484213308

More Books

Students also viewed these Databases questions

Question

=+2. What is the difference between brand voice and tone?

Answered: 1 week ago