DIV BL divides the 16-bit AX by the byte BL. The quotient goes to AL and the remainder to AH, so one instruction gives both results.
What to build
Read two digits, n and d, and print the quotient and the remainder of n ÷ d.
Requirements
- Divide the first digit by the second with DIV.
- Print the quotient, a space, then the remainder, each as one digit.
- The second digit is never 0.
Input
Two digits, then Enter. The second digit is 1 to 9.
Output
One line: the quotient, a space and the remainder, for example 2 1 for 7 and 3.
Constraints
0 ≤ n ≤ 9, 1 ≤ d ≤ 9.
Example
Input:
73
Output:
2 1
Why it works
DIV BL works on AX, so a leftover value in AH would change the number to be divided: AH must be 0 first. The division gives n = quotient × d + remainder, and the remainder is always less than d, so both fit in one digit here.
Examples
73
2 1
99
1 0
Hints
Hint 1
Read the first digit into AL and the second into BL, and turn both into numbers with SUB '0'.
Hint 2
DIV BL divides AX by BL, so clear AH first: MOV AH, 0. Then the quotient is in AL and the remainder in AH.
Hint 3
Save both in other registers before the next INT 21h, which changes AX.
Solution
Show one correct solution (try it yourself first)
; Quotient and remainder
.MODEL SMALL
.STACK 100H
.CODE
MAIN PROC
MOV AH, 1
INT 21H
SUB AL, '0'
MOV CL, AL ; n
INT 21H
SUB AL, '0'
MOV BL, AL ; d
MOV AL, CL
MOV AH, 0 ; AX = n
DIV BL ; AL = quotient, AH = remainder
MOV BX, AX ; keep both: INT 21h changes AX
MOV DL, BL
ADD DL, '0'
MOV AH, 2
INT 21H
MOV DL, ' '
INT 21H
MOV DL, BH
ADD DL, '0'
INT 21H
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN
▶ Open this solution in the compiler, then press Visualize to watch it run step by step