89 lines
817 B
C
89 lines
817 B
C
|
|
||
|
/*
|
||
|
r0 = bin
|
||
|
r1 = bcd
|
||
|
r7 = len of bin
|
||
|
r6 = len of bcd
|
||
|
*/
|
||
|
|
||
|
#include "mc8051fun.h"
|
||
|
|
||
|
// double dabble
|
||
|
|
||
|
void long_xtobcd() __naked
|
||
|
{
|
||
|
__asm
|
||
|
.globl long_xtobcd
|
||
|
|
||
|
long_xtobcd:
|
||
|
|
||
|
; fill dst with zeroes
|
||
|
|
||
|
mov r3,AR1 ; save r1 in r3
|
||
|
mov r4,AR6 ; use r4 as counter
|
||
|
mov a,#0x00
|
||
|
|
||
|
000$:
|
||
|
movx @r1,a
|
||
|
inc r1
|
||
|
djnz r4,000$
|
||
|
|
||
|
mov a,r0
|
||
|
add a,r7
|
||
|
dec a
|
||
|
mov r0,a
|
||
|
mov r2,AR0 ; save r0 in r2
|
||
|
|
||
|
006$:
|
||
|
movx a,@r0
|
||
|
mov r5,#0x08
|
||
|
005$:
|
||
|
mov r4,AR6 ; use r4 as counter
|
||
|
mov r1,AR3
|
||
|
|
||
|
push ACC
|
||
|
004$:
|
||
|
movx a,@r1
|
||
|
acall 003$
|
||
|
acall 003$
|
||
|
movx @r1,a
|
||
|
inc r1
|
||
|
djnz r4,004$
|
||
|
|
||
|
pop ACC
|
||
|
|
||
|
|
||
|
rlc a
|
||
|
push ACC
|
||
|
push AR0
|
||
|
push AR7
|
||
|
mov r7,AR6
|
||
|
mov r0,AR3
|
||
|
lcall long_xrlc
|
||
|
pop AR7
|
||
|
pop AR0
|
||
|
pop ACC
|
||
|
djnz r5,005$
|
||
|
|
||
|
|
||
|
dec r0
|
||
|
djnz r7,006$
|
||
|
ret
|
||
|
|
||
|
|
||
|
003$:
|
||
|
swap a
|
||
|
clr c
|
||
|
subb a,#0x50
|
||
|
jc 002$
|
||
|
add a,#0x30
|
||
|
002$:
|
||
|
add a,#0x50
|
||
|
ret
|
||
|
|
||
|
__endasm;
|
||
|
}
|
||
|
|
||
|
|
||
|
|