;Division d'un binaire 32bits/16bits ;Entrée dividende R3:R2:R1:R0 ;Entrée diviseur R21:R20 ;Sortie résultat R3:R2:R1:R0 ;Reste R7:R6:R5:R4 ; .DEF a0 = R0 ;Octet bas dividende/réponse ; .DEF a1 = R1 ;To hold second-byte of answer ; .DEF a2 = R2 ;To hold third-byte of answer ; .DEF a3 = R3 ;To hold fourth-byte of answer ; .DEF b0 = R4 ;Octet bas du reste ; .DEF b1 = R5 ;To hold second-byte of remainder ; .DEF b2 = R6 ;To hold third-byte of remainder ; .DEF b3 = R7 ;To hold fourth-byte of remainder ; .DEF buffer = R8 ;To hold the value Zéro ; .def count=R17 ;Bit Counter ; .DEF A = R16 ;registre général .DEF BL = R21 ;Octet bas du diviseur .DEF BM = R22 .DEF BH = R23 ;To hold high-byte of divisor ; LDI A,LOW(420) ;Load low-byte of dividend into A1 ; mov a0,A ; LDI A,BYTE2(420) ;Load second-byte of dividend into A2 ; mov a1,A ; LDI A,BYTE3(420) ;Load third-byte of dividend into A3 ; mov a2,A ; LDI A,BYTE4(420) ;Load fourth-byte of dividend into A4 ; mov a3,A ; LDI BL,LOW(10) ;Load low-byte of divisor into BL ; LDI BH,HIGH(10) ;Load high-byte of divisor into BH DIV3224: CLR buffer ;MOVW a1:a0,A2:A1 ;Copy dividend into answer ;MOVW a3:a2,A4:A3 ; LDI count,33 ;Load bit counter SUB b0,b0 ;Clear Remainder and Carry CLR b1 ; CLR b2 ; CLR b3 ; LOOP: ROL a0 ;Shift the answer to the left ROL a1 ; ROL a2 ; ROL a3 ; DEC count ;Decrement Counter BREQ DONE ;Exit if 32 bits done ROL b0 ;Shift remainder to the left ROL b1 ; ROL b2 ; ROL b3 ; SUB b0,BL ;Try to subtract divisor from remainder SBC b1,BM ; SBC b2,BH ; SBC b3,buffer ; BRCC SKIP ;If the result was negative then ADD b0,BL ;reverse the subtraction to try again ADC b1,BM ; ADC b2,BH ; ADC b3,buffer ; CLC ;Clear Carry Flag so buffer shifted into A RJMP LOOP ;Loop Back SKIP: SEC ;Set Carry Flag to be shifted into A RJMP LOOP DONE: ret