Division of Two 8 Bit Number
Sunny Bhaskar
11/6/20241 min read
Algorithm
Load the dividend (04H) into the accumulator.
Load the divisor (02H) into register B.
Initialize register C to 00H to store the quotient.
Perform the following in a loop until the value in the accumulator becomes less than B:
Subtract B from the accumulator.
Increment the quotient in C.
After exiting the loop, the accumulator holds the remainder, and register C holds the quotient.
Store the quotient in a specified memory location (e.g., 2053H) and the remainder in another memory location (e.g., 2054H).
Halt the program.
Program
MVI A, 04H ; Load 04H into accumulator A (dividend)
MVI B, 02H ; Load 02H into register B (divisor)
MVI C, 00H ; Clear C to store the quotient
DIV_LOOP:
CMP B ; Compare A with B
JC DIV_DONE ; If A < B, jump to DIV_DONE
SUB B ; A = A - B
INR C ; Increment quotient
JMP DIV_LOOP ; Repeat loop
DIV_DONE:
STA 2053H ; Store the quotient (02H) at memory location 2053H
MOV D, A ; Move remainder to D
STA 2054H ; Store the remainder (00H) at memory location 2054H
HLT ; Halt the program