|
Subject: [stella] Hex to BCD conversion routine From: Kevin Horton <khorton@xxxxxxxxxx> Date: Sat, 10 Feb 2001 18:43:49 -0500 |
Here's my favourite hex to BCD routine for the 6502. I use Table Assembler, so if you think the code looks a bit funny, that's why. :-)
;HEX2BCD.ASM ;How to use: ; ;Load your binary number between 0000 and ffff into inp0 and inp1. ;MSB goes into inp1.
;run conv_bcd and get your output in packed BCD format in bcd_out0-2 ; bcd_out2 is MSB, only lower nybble is used. ;
bcd_out0: .block 1 bcd_out1: .block 1 bcd_out2: .block 1 inp0: .block 1 inp1: .block 1
conv_bcd: ldx #16 lda #0 sta bcd_out0 sta bcd_out1 sta bcd_out2 ;clear result regs
b2bcd: clc
rol inp0
rol inp1
rol bcd_out2
rol bcd_out1
rol bcd_out0 ;rotate results
dex
beq bc_done
ldy #bcd_out2
jsr bcdfix
ldy #bcd_out1
jsr bcdfix
ldy #bcd_out0
jsr bcdfix
jmp b2bcdbcdfix: lda 0,y
clc
adc #003h
and #008h
beq bcd_f2
lda 0,y
clc
adc #003h
sta 0,ybcd_f2: lda 0,y
clc
adc #030h
and #080h
beq bc_done
lda 0,y
clc
adc #030h
sta 0,y
- Archives (includes files) at http://www.biglist.com/lists/stella/archives/ Unsub & more at http://www.biglist.com/lists/stella/
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [stella] Binary to Decimal rout, Greg Miller | Thread | Re: [stella] double-height 6-digit , Thomas Jentzsch |
| Re: [stella] double-height 6-digit , bwmott | Date | [stella] Qb: Latest version v0.01, Andrew Davie |
| Month |