Question: fix the multiplcation part of this code and also display the corrrect sum when the answer is over 9 . model small . stack 1
fix the multiplcation part of this code and also display the corrrect sum when the answer is over
model small
stack h ; Define stack size
data
menumsg db Add", Multiply", Exit", $
choicemsg db "Enter your choice: $
resultmsg db "Result: $
newline db $
num db ; Define variables to store numbers
num db
sum dw ; Wordsized variable to store result
errormsg db "Invalid choice! Please try again.", $
addmsg db "You selected addition.$
multiplymsg db "You selected multiplication.$
code
main:
mov ax @data
mov ds ax
menu:
; Display the menu
mov ah
lea dx menumsg
int h
; Read user's choice
mov ah
int h
mov bl al
; Check the choice and execute accordingly
cmp bl
je addnumbers
cmp bl
je multiplynumbers
cmp bl
je skipdisplay ; Jump to skipdisplay if choice is
; If choice is invalid, display error message and go back to menu
jmp invalidchoice
skipdisplay:
jmp exitprogram ; Jump to exitprogram if choice is
invalidchoice:
; Display error message for invalid choice
mov ah
lea dx errormsg
int h
jmp menu
addnumbers:
; Display the selected option
mov ah
lea dx addmsg
int h
; Prompt for the first number
mov ah
lea dx choicemsg
int h
; Read the first number
mov ah
int h
sub al
mov num al
; Prompt for the second number
mov ah
lea dx choicemsg
int h
; Read the second number
mov ah
int h
sub al
mov num al
; Calculate the sum
mov al num
add al num
mov sum, ax ; Store the sum
; Display the sum
mov ah
lea dx resultmsg
int h
; Display the sum result
mov dl al
add dl
mov ah
int h
jmp menu
multiplynumbers:
; Display the selected option
mov ah
lea dx multiplymsg
int h
; Prompt for the first number
mov ah
lea dx choicemsg
int h
; Read the first number
mov ah
int h
sub al
mov num al
; Prompt for the second number
mov ah
lea dx choicemsg
int h
; Read the second number
mov ah
int h
sub al
mov num al
; Multiply the numbers
mov al num
mul num
; Store the result in a wordsized variable
mov sum, ax
; Display the multiplication result
mov bx ; To convert the result to decimal
mov cx ; For counting digits
mov dx ; Remainder
; Display the result
mov ah
lea dx resultmsg
int h
; Display the high part of the result
mov ax sum
mov dx ; Clear DX before division
div bx ; Divide AX by
add dl ; Convert remainder to ASCII
mov ah
int h
; Display the low part of the result
mov dl al
add dl
mov ah
int h
jmp menu
exitprogram:
; Exit the program
mov ahCh
int h
end main
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
