; Div8_8 ; Version 1.0 ; Date: November 11, 2014 ; Written By : Yoseph Yegezu ; From text book 'The AVR Microcontroller and Embedded systems'Chapter 5 Page 167 .INCLUDE .CSEG .DEF Num=R20 .DEF Denominator=R21 .DEF Quotient=R22 .ORG 0x0000 ldi Num, 0xAA ldi Denominator, 0x55 //call the 8 bit division rcall Div8 ret /************************************ * subroutine divides unside 8bit by 8bit * Quotient = Numerator/Denominator * * r22 = r20 / r21 * with remainder in r20 * ************************************/ Div8: clr Quotient // r22 // quotient is going to increment by 1 everytime L1 loops // loop L1 stops when the numerator-denominator = less than the demoninator L1: inc Quotient sub Num,Denominator // r20,r21 brcc L1 //since the quotient is incremented by 1 when the loop began, after the loop quotient is dec dec Quotient //notice L1 is going to branch off when the numerator is no lnger divisiable by the denominator //which means L1 is branching off when numerator-denominator results in a negative value. //therefore, the denominator is going to be added to the numerator after the loop. add Num,Denominator // r20,r21 ret