/* Write a function to convert a packed BCD number * in register r24 into its binary equivalent. * Return 8-bit binary result in register r24. * For example if r24 = 32 then result r24 = 3 x 10 + 2 * * Source: Beginners Introduction to the Assembly Language of ATMEL­AVR­Microprocessors * http://www.ic.unicamp.br/~celio/mc404-2008/docs/beginner_avr.pdf */ .INCLUDE BCDtoBINARY: ; Conversion of packed BCD number to 8-bit Binary (0 to 99) push r15 ; save contents of registers modified by this subroutine in r15, SREG push r16 push r25 mov r25,r24 ; copy the number to another register. swap r25 ; exchange upper and the lower nibbles cbr r25,0xF0 ; clear upper BCD nibble cbr r24,0xF0 ; clear lower BCD nibble ldi r16,0x0A ; 10 mul r25,r16 ; r1:r0 = 10's place (result 0 to 90) add r24,r0 ; add to 1's place pop r25 pop r16 out SREG, r15 pop r15 ret