[an error occurred while processing this directive]
[an error occurred while processing this directive]
|
;A simple algorithm to convert binary to BCD is:
;1. Add 3 to every BCD nibble that's >=5
;2. Shift left
;Repeat until binary portion is all 0000
;Example: Convert $F9 to BCD
;0000 0000 0000 : 1111 1001
;0000 0000 0001 : 1111 0010 (shift left)
;0000 0000 0011 : 1110 0100 (shift left)
;0000 0000 0111 : 1100 1000 (shift left)
;0000 0000 1010 : 1100 1000 (add 3)
;0000 0001 0101 : 1001 0000 (shift left)
;0000 0001 1000 : 1001 0000 (add 3)
;0000 0011 0001 : 0010 0000 (shift left)
;0000 0110 0010 : 0100 0000 (shift left)
;0000 1001 0010 : 0100 0000 (add 3)
;0001 0010 0100 : 1000 0000 (shift left)
;0010 0100 1001 : 0000 0000 (shift left)
;And the left now holds BCD 249.
;MUCH easier than messing with IDIV and FDIV!!!
Алгоритм, кстати обратимый. Если очень нужно, могу порыться в проектах и найти подпрограммы на асме для PIC и AVR (для разного кол-ва байт).
Для AVR написано с возможностью вызывать из IAR-C
E-mail: info@telesys.ru