Q. Write a program for division of two numbers. Assume that the numbers are in memory
location C000H and C001H, and the quotient and remainder is to be displayed at output
devices 50H and 51H.
Solution:
LXI H, C000H
MOV A, M ; dividend in A from C000H
INX H
MOV B, M ; divisor in B from C001H
MVI C, 00H ; quotient in C
LABEL1: CMP B
JC LABEL2 ; if dividend<divisor, no division
INR C
SUB B
JNZ LABEL1
LABEL2: OUT 51H ; display remainder
MOV A, C
OUT 50H ; display quotient
HLT
location C000H and C001H, and the quotient and remainder is to be displayed at output
devices 50H and 51H.
Solution:
LXI H, C000H
MOV A, M ; dividend in A from C000H
INX H
MOV B, M ; divisor in B from C001H
MVI C, 00H ; quotient in C
LABEL1: CMP B
JC LABEL2 ; if dividend<divisor, no division
INR C
SUB B
JNZ LABEL1
LABEL2: OUT 51H ; display remainder
MOV A, C
OUT 50H ; display quotient
HLT
Comments
Post a Comment