93 lines
876 B
C
93 lines
876 B
C
|
|
/*
|
|
r0 = bin
|
|
r1 = bcd
|
|
r7 = len of bin
|
|
r6 = len of bcd
|
|
*/
|
|
|
|
#include "mc8051fun.h"
|
|
|
|
#include "usebank0.h"
|
|
|
|
// double dabble
|
|
|
|
void long_tobcd__() __naked
|
|
{
|
|
__asm
|
|
.globl long_tobcd
|
|
|
|
long_tobcd:
|
|
|
|
; fill dst with zeroes
|
|
|
|
mov r3,AR1 ; save r1 in r3
|
|
mov r4,AR6 ; use r4 as counter
|
|
; mov a,#0x00
|
|
|
|
000$:
|
|
mov @r1,#0x0
|
|
inc r1
|
|
djnz r4,000$
|
|
|
|
|
|
|
|
mov a,r0
|
|
add a,r7
|
|
dec a
|
|
mov r0,a ; r0 points to last byte of bin
|
|
mov r2,AR0 ; save r0 in r2
|
|
|
|
006$:
|
|
mov a,@r0
|
|
mov r5,#0x08
|
|
005$:
|
|
mov r4,AR6 ; use r4 as counter
|
|
mov r1,AR3
|
|
|
|
push ACC
|
|
004$:
|
|
mov a,@r1
|
|
acall 003$
|
|
acall 003$
|
|
mov @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_rlc
|
|
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;
|
|
}
|
|
|
|
|
|
|