Question: This is assembly language code, it has no warning or errors but doesn't run as expected. This program asks the user for 2 numbers that

This is assembly language code, it has no warning or errors but doesn't run as expected. This program asks the user for 2 numbers that are only from 0 to 9. Then should print all the results from the operations which are add, subtract, divide and multiply these 2 numbers. Please fix. Here is the code:

.model small .stack 100h

.data prompt1 db 10,13,'Enter first digit: $' prompt2 db 10,13,'Enter second digit: $' result dw ?

.code main proc mov ax, @data mov ds, ax

call GET_FIRST_DIGIT call GET_SECOND_DIGIT

; Automatically perform all four arithmetic operations mov bx, ax mov cx, dx

; Addition add ax, cx mov result, ax call SHOW_RESULT

; Subtraction mov ax, bx sub ax, cx mov result, ax call SHOW_RESULT

; Multiplication mov ax, bx mul cx mov result, ax call SHOW_RESULT

; Division mov ax, bx div cx mov result, ax call SHOW_RESULT

ret main endp

; get the first digit GET_FIRST_DIGIT proc ; display the prompt lea dx, prompt1 call DISPLAY_PROMPT

; get the digit call GET_DIGIT ret GET_FIRST_DIGIT endp

; get the second digit GET_SECOND_DIGIT proc ; display the prompt lea dx, prompt2 call DISPLAY_PROMPT

; get the digit call GET_DIGIT ret GET_SECOND_DIGIT endp

; display the result SHOW_RESULT proc ; display the result mov dx, result call DISPLAY_NUMBER ret SHOW_RESULT endp

; display a prompt DISPLAY_PROMPT proc ; display the prompt mov ah, 9 int 21h ret DISPLAY_PROMPT endp

; get a digit GET_DIGIT proc ; get the digit call GET_CHAR sub al, 48 mov ah, 0 ret GET_DIGIT endp

GET_CHAR proc ; get the character mov ah, 1 int 21h cmp al, 13 je EXIT_GET_CHAR cmp al, 10 je EXIT_GET_CHAR jmp GET_CHAR

EXIT_GET_CHAR: ret GET_CHAR endp

; display a number DISPLAY_NUMBER proc ; get the number of digits in the result mov cx, result mov bx, 10 xor dx, dx mov bp, 0 div bx inc bp cmp dx, 0 jne @F

@B: ; get the current digit mov dx, cx mov ax, 10 mul bp div ax add dl, 48 ; display the digit call DISPLAY_DIGIT ; prepare for next digit dec bp mov cx, ax cmp ax, 0 jne @B

jmp @E

@F: inc bp jmp @B

@E: ret DISPLAY_NUMBER endp

DISPLAY_DIGIT PROC mov ah, 2 int 21h ret

DISPLAY_DIGIT ENDP

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 Databases Questions!