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 9
.model small
.stack 100h ; Define stack size
.data
menu_msg db 13,10,"1. Add", 13,10,"2. Multiply", 13,10,"3. Exit", 13,10,"$"
choice_msg db 13,10, "Enter your choice: $"
result_msg db 13,10, "Result: $"
newline db 13,10,'$'
num1 db ? ; Define variables to store numbers
num2 db ?
sum dw ? ; Word-sized variable to store result
error_msg db 13,10, "Invalid choice! Please try again.", 13,10,"$"
add_msg db 13,10, "You selected addition.$"
multiply_msg db 13,10, "You selected multiplication.$"
.code
main:
mov ax, @data
mov ds, ax
menu:
; Display the menu
mov ah,9
lea dx, menu_msg
int 21h
; Read user's choice
mov ah,1
int 21h
mov bl, al
; Check the choice and execute accordingly
cmp bl,'1'
je add_numbers
cmp bl,'2'
je multiply_numbers
cmp bl,'3'
je skip_display ; Jump to skip_display if choice is '3'
; If choice is invalid, display error message and go back to menu
jmp invalid_choice
skip_display:
jmp exit_program ; Jump to exit_program if choice is '3'
invalid_choice:
; Display error message for invalid choice
mov ah,9
lea dx, error_msg
int 21h
jmp menu
add_numbers:
; Display the selected option
mov ah,9
lea dx, add_msg
int 21h
; Prompt for the first number
mov ah,9
lea dx, choice_msg
int 21h
; Read the first number
mov ah,1
int 21h
sub al,'0'
mov num1, al
; Prompt for the second number
mov ah,9
lea dx, choice_msg
int 21h
; Read the second number
mov ah,1
int 21h
sub al,'0'
mov num2, al
; Calculate the sum
mov al, num1
add al, num2
mov sum, ax ; Store the sum
; Display the sum
mov ah,9
lea dx, result_msg
int 21h
; Display the sum result
mov dl, al
add dl,'0'
mov ah,2
int 21h
jmp menu
multiply_numbers:
; Display the selected option
mov ah,9
lea dx, multiply_msg
int 21h
; Prompt for the first number
mov ah,9
lea dx, choice_msg
int 21h
; Read the first number
mov ah,1
int 21h
sub al,'0'
mov num1, al
; Prompt for the second number
mov ah,9
lea dx, choice_msg
int 21h
; Read the second number
mov ah,1
int 21h
sub al,'0'
mov num2, al
; Multiply the numbers
mov al, num1
mul num2
; Store the result in a word-sized variable
mov sum, ax
; Display the multiplication result
mov bx,10 ; To convert the result to decimal
mov cx,0 ; For counting digits
mov dx,0 ; Remainder
; Display the result
mov ah,9
lea dx, result_msg
int 21h
; Display the high part of the result
mov ax, sum
mov dx,0 ; Clear DX before division
div bx ; Divide AX by 10
add dl,'0' ; Convert remainder to ASCII
mov ah,2
int 21h
; Display the low part of the result
mov dl, al
add dl,'0'
mov ah,2
int 21h
jmp menu
exit_program:
; Exit the program
mov ah,4Ch
int 21h
end main

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!