.z80 aseg org 0100h Test: ld c,5 ld hl,1202 call Divide rst 38h ;---------------------------------------------------------------------- ; Divide (20_Mar_84) ;------------------- ; 1) Register Usage ; A -> On Exit = Remainder ; C -> Divisor ; HL -> On Entry = Dividend; On Exit = Result ; Divide: ld a,h ;If (Dividend eq 0) or l ret z ; Return (A:=0, HL:=0) ld b,17 ;B:= Loop Counter DivLp0: dec b ;Repeat Decrement the loop counter add hl,hl ; Shift the result jp nc,DivLp0 ;Until (Msb of result is in carry) ld a,0 ;A:= 0 DivLp1: rla ;Repeat shift next bit into accm sub c ; Accm:= Accm - Number of Heads ccf jr c,Next ; If (there was an underflow) adc a,c ; Restore the accm or a ; (clear the carry) Next: adc hl,hl ; Incorperate the partial result djnz divLp1 ;Until (Loop Counter eq 0) ret ;Return end