Question: 4 . Write a program called p 3 . asm that is similar to programs 1 and 2 , except that this program uses IDIV
Write a program called pasm that is similar to programs and 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:
Please enter a single digit number:
The quotient is:
The remainder is:
Here is what I have done so far, Im trying to divide the numbers but it won't work
BITS
SECTION data
startmsg db "The Dividing Program"
len equ $ startmsg
addmsg db "Please enter a single digit number:
len equ $ addmsg
addmsg db "Please enter a single digit number:
len equ $ addmsg
resultmsg db "The quotient is:
len equ $ resultmsg
remmsg db "The remainder is:
len equ $ remmsg
newline db xA
SECTION bss
numstore resb
numstore resb
result resb
rem resb
SECTION text
global start
start:
;Starting message
mov eax, ;sys callsyswrite
mov ebx, ; sys callstdout
mov ecx, startmsg ;The message
mov edx, len ; length of message
int x ; call kernel
;Newline command
mov eax,
mov ebx,
mov ecx, newline
mov edx,
int x
;Step : Prompt the user with a single digit number
mov eax, ;sys callsyswrite
mov ebx, ; sys callstdout
mov ecx, addmsg ; The message
mov edx, len ; length of message
int x ; call kernel
;Read in the first number
mov eax,
mov ebx,
mov ecx, numstore
mov edx,
int x
;Prompt user for the second number
mov eax,
mov ebx,
mov ecx, addmsg
mov edx, len
int x
;Read in the second number
mov eax,
mov ebx,
mov ecx, numstore
mov edx,
int x
;Convert the first number from ASCII to integer
mov axnumstore
sub ax
;Convert the second number from ASCII to integer then add to first number
mov bxnumstore
sub bx
;Divide the second number from the first number
idiv ax
;Convert the answer from a number to a string
add al
add ah
mov result al
mov rem ah
;Print result message
mov eax,
mov ebx,
mov ecx, resultmsg
mov edx, len
int x
;Print the result
mov eax,
mov ebx,
mov ecx, result
mov edx,
int x
;Print remainder message
mov eax,
mov ebx,
mov ecx, remmsg
mov edx, len
int x
;Print the remainder
mov eax,
mov ebx,
mov ecx, rem
mov edx,
int x
mov eax,
mov ebx,
mov ecx, newline
mov edx,
int x
mov eax,
int x properly.
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
