Question: 4 . Write a program called p 3 . asm that is similar to programs 1 and 2 , except that this program uses IDIV

4. Write a program called p3.asm that is similar to programs 1 and 2, except that this program uses IDIV to divide the first number by the second number. IDIV is similar to IMUL. However, the quotient will be stored in AL, and the remainder will be stored in AH. Your program should print "The quotient is: " followed by the quotient on a single line, and "The remainder is: " followed by the remainder on a single line. Here is the expected output.
The Dividing Program
Please enter a single digit number: 6
Please enter a single digit number: 2
The quotient is: 3
The remainder is: 0
Here is what I have done so far, I'm trying to divide the numbers but it won't work
BITS 32
SECTION .data
startmsg db "The Dividing Program"
len1 equ $ - startmsg
add1msg db "Please enter a single digit number: ",0
len2 equ $ - add1msg
add2msg db "Please enter a single digit number: ",0
len3 equ $ - add2msg
resultmsg db "The quotient is: ",0
len4 equ $ - resultmsg
remmsg db "The remainder is: ",0
len5 equ $ - remmsg
newline db 0xA
SECTION .bss
numstore1 resb 1
numstore2 resb 1
result resb 1
rem resb 1
SECTION .text
global _start
_start:
;Starting message
mov eax, 4 ;sys call(sys_write)
mov ebx, 1 ; sys call(std_out)
mov ecx, startmsg ;The message
mov edx, len1 ; length of message
int 0x80 ; call kernel
;Newline command
mov eax, 4
mov ebx, 1
mov ecx, newline
mov edx, 1
int 0x80
;Step 1: Prompt the user with a single digit number
mov eax, 4 ;sys call(sys_write)
mov ebx, 1 ; sys call(std_out)
mov ecx, add1msg ; The message
mov edx, len2 ; length of message
int 0x80 ; call kernel
;Read in the first number
mov eax, 3
mov ebx, 0
mov ecx, numstore1
mov edx, 2
int 0x80
;Prompt user for the second number
mov eax, 4
mov ebx, 1
mov ecx, add2msg
mov edx, len3
int 0x80
;Read in the second number
mov eax, 3
mov ebx, 0
mov ecx, numstore2
mov edx, 2
int 0x80
;Convert the first number from ASCII to integer
mov ax,[numstore1]
sub ax,'0'
;Convert the second number from ASCII to integer then add to first number
mov bx,[numstore2]
sub bx,'0'
;Divide the second number from the first number
idiv ax
;Convert the answer from a number to a string
add al,'0'
add ah,'0'
mov [result], al
mov [rem], ah
;Print result message
mov eax, 4
mov ebx, 1
mov ecx, resultmsg
mov edx, len4
int 0x80
;Print the result
mov eax, 4
mov ebx, 1
mov ecx, result
mov edx, 2
int 0x80
;Print remainder message
mov eax, 4
mov ebx, 1
mov ecx, remmsg
mov edx, len5
int 0x80
;Print the remainder
mov eax, 4
mov ebx, 1
mov ecx, rem
mov edx, 1
int 0x80
mov eax, 4
mov ebx, 1
mov ecx, newline
mov edx, 1
int 0x80
mov eax, 1
int 0x80 properly.
4 . Write a program called p 3 . asm that is

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