;32-bit unsigned binary integer to 8-bit BCD in AVR ASM for ATtiny ;Entrée : a3:a2:a1:a0 ;Sortie : b3:b2:b1:b0 ; .def a0 = r0 ; .def a1 = r1 ; .def a2 = r2 ; .def a3 = r3 ; .def b0 = r4 ; .def b1 = r5 ; .def b2 = r6 ; .def b3 = r7 ; .def A = r16 ; .def buffer=r8 ; .def count=r17 BIN2DCB32: clr b0 clr b1 clr b2 clr b3 LDI count,32 ;Compteur de bit 32 shift BCD8: ;8 octals CLC ROL a0 ;peu importe le carry ROL a1 ROL a2 ROL a3 ROL b0 ROL b1 ROL b2 ROL b3 dec count brne tst8o ;si <>32 test sinon ret ret tst8o: mov buffer,b0 rcall tst2o ;rcall test 2 octals mov b0,buffer mov buffer,b1 rcall tst2o ;rcall test 2 octals mov b1,buffer mov buffer,b2 rcall tst2o ;rcall test 2 octals mov b2,buffer mov buffer,b3 rcall tst2o ;rcall test 2 octals mov b3,buffer rjmp BCD8 tst2o: ldi A,0x0F and A,buffer cpi A,5 brlo tst1o ;a<5 test 1 octal bas ldi A,0x03 ;si>=5 enlève 0x03 add buffer,A tst1o: ldi A,0xF0 and A,buffer swap A cpi A,5 brlo endtst2o ;a<5 test 1 octal haut ldi A,0x30 add buffer,A ;si>=5 enlève 0x30 endtst2o: ret