MOV A,R3 ADD A,R2 JZ interrupt --------------------------------------------------------------------- Don't understand from here --------------------------------------------------------------------- div16_16: CLR C ;Clear carry initially MOV R4,#00h ;Clear R4 working variable initially MOV R5,#00h ;CLear R5 working variable initially MOV R6,#00h MOV 20h, R1 ;Save high-bit of the dividend MOV 21h, R0 ;Save low-bit of the dividend MOV 30h, R3 ;Save high-bit of the divisor MOV 31h, R2 ;Save low-bit of the divisor MOV B,#00h ;Clear B since B will count the number of left-shifted bits div1: INC B ;Increment counter for each left shift MOV A,R2 ;Move the current divisor low byte into the accumulator RLC A ;Shift low-byte left, rotate through carry to apply highest bit to high-byte MOV R2,A ;Save the updated divisor low-byte MOV A,R3 ;Move the current divisor high byte into the accumulator RLC A ;Shift high-byte left high, rotating in carry from low-byte MOV R3,A ;Save the updated divisor high-byte JNC div1 ;Repeat until carry flag is set from high-byte div2: ;Shift right the divisor MOV A,R3 ;Move high-byte of divisor into accumulator RRC A ;Rotate high-byte of divisor right and into carry MOV R3,A ;Save updated value of high-byte of divisor MOV A,R2 ;Move low-byte of divisor into accumulator RRC A ;Rotate low-byte of divisor right, with carry from high-byte MOV R2,A ;Save updated value of low-byte of divisor CLR C ;Clear carry, we don't need it anymore MOV 07h,R1 ;Make a safe copy of the dividend high-byte MOV 06h,R0 ;Make a safe copy of the dividend low-byte MOV A,R0 ;Move low-byte of dividend into accumulator SUBB A,R2 ;Dividend - shifted divisor = result bit (no factor, only 0 or 1) MOV R0,A ;Save updated dividend MOV A,R1 ;Move high-byte of dividend into accumulator SUBB A,R3 ;Subtract high-byte of divisor (all together 16-bit substraction) MOV R1,A ;Save updated high-byte back in high-byte of divisor JNC div3 ;If carry flag is NOT set, result is 1 MOV R1,07h ;Otherwise result is 0, save copy of divisor to undo subtraction MOV R0,06h div3: CPL C ;Invert carry, so it can be directly copied into result MOV A,R4 RLC A ;Shift carry flag into temporary result MOV R4,A MOV A,R5 RLC A MOV R5,A DJNZ B,div2 ;Now count backwards and repeat until "B" is zero MOV R3,05h ;Move result to R3/R2 MOV R2,04h ;Move result to R3/R2 MOV R6,#00h MOV 23h, R3 ;send high-bit of the quotient in the data memory MOV 24h, R2 ;send low-bit of the quotient in the data memory MOV 33h, R1 ;send high-bit of the remainder in the data memory MOV 34h, R0 ;send low-bit of the remainder in the data memory RET --------------------------------------------------------------------- to here --------------------------------------------------------------------- interrupt: HALT: SJMP HALT ;break for a divisor equal to 0