;SUPPOSE, We are going to divide 2050h by 1630h.
LXI H,0000H
SPHL
;SP holds quotient.
LXI H,2050H
;HL holds the dividend.
LXI B,1630H
;BC holds the divisor.
AGAIN: MOV A,H
CMP D
JC LAST
JZ CHKNXT
JMP DIVIDE
CHKNXT: MOV A,L
CMP C
JNC DIVIDE
JMP LAST
;Up to this, we have compared dividend with divisor.
DIVIDE: INX SP
;Now, HL <- HL - BC = HL + ((complement of BC) + 1)
;HL <- HL + DE + 1
MOV A,B
CMA
MOV D,A
MOV A,C
CMA
MOV E,A
INX D
DAD HL
;Finally, HL holds the remainder.
JMP AGAIN
LAST: HLT
LXI H,0000H
SPHL
;SP holds quotient.
LXI H,2050H
;HL holds the dividend.
LXI B,1630H
;BC holds the divisor.
AGAIN: MOV A,H
CMP D
JC LAST
JZ CHKNXT
JMP DIVIDE
CHKNXT: MOV A,L
CMP C
JNC DIVIDE
JMP LAST
;Up to this, we have compared dividend with divisor.
DIVIDE: INX SP
;Now, HL <- HL - BC = HL + ((complement of BC) + 1)
;HL <- HL + DE + 1
MOV A,B
CMA
MOV D,A
MOV A,C
CMA
MOV E,A
INX D
DAD HL
;Finally, HL holds the remainder.
JMP AGAIN
LAST: HLT
No comments:
Post a Comment