Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > 32bit Decimal convertion
2018-10-05 07:02
JackAsser

Registered: Jun 2002
Posts: 1990
32bit Decimal convertion

Anybody got this shitz for 32-bit numbers? http://codebase64.org/doku.php?id=base:hexadecimal_to_decimal_c..
 
... 26 posts hidden. Click here to view all posts....
 
2018-10-23 14:48
Zirias

Registered: Jan 2014
Posts: 48
For the score display in 8192, I decided to create something reusable, although I needed it for 32 bit -- this should work for anything up to 128 bit if you adjust the constants, output is right-aligned and padded with spaces (0-padding would simplify it further):

.export numtostring
.exportzp nc_string
.exportzp nc_num

NUMSTRSIZE	= $a
NUMSIZE		= $4

.zeropage

nc_string:	.res	NUMSTRSIZE
nc_num:		.res	NUMSIZE

.code

numtostring:
		ldy	#NUMSTRSIZE
		lda	#$0
nts_fillzero:	sta	nc_string-1,y
		dey
		bne	nts_fillzero
		ldy	#(NUMSIZE*8)
nts_bcdloop:	ldx	#(NUMSTRSIZE-2)
nts_addloop:	lda	nc_string+1,x
		cmp	#$5
		bmi	nts_noadd
		adc	#$2
		sta	nc_string+1,x
nts_noadd:	dex
		bpl	nts_addloop
		asl	nc_num
		ldx	#($ff-NUMSIZE+2)
nts_rol:	rol	nc_num+NUMSIZE,x
		inx
		bne	nts_rol
		ldx	#(NUMSTRSIZE-2)
nts_rolloop:	lda	nc_string+1,x
		rol	a
		cmp	#$10
		and	#$f
		sta	nc_string+1,x
nts_rolnext:	dex
		bpl	nts_rolloop
		dey
		bne	nts_bcdloop
nts_scan:	cpx	#(NUMSTRSIZE-1)
		beq	nts_digits
		inx
		lda	nc_string,x
		bne	nts_digits
		lda	#$20
		sta	nc_string,x
		bne	nts_scan
nts_digits:	lda	nc_string,x
		ora	#$30
		sta	nc_string,x
		inx
		cpx	#(NUMSTRSIZE)
		bne	nts_digits
		rts
Previous - 1 | 2 | 3 | 4 - Next
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Fred/Channel 4
rexbeng
HOL2001/Quantum
Martin Piper
zscs
Zartan/Unit 5
TheRyk/MYD!
Guests online: 123
Top Demos
1 Next Level  (9.8)
2 13:37  (9.7)
3 Mojo  (9.7)
4 50 Years of Flex  (9.7)
5 Coma Light 13  (9.7)
6 Edge of Disgrace  (9.6)
7 Comaland 100%  (9.6)
8 Uncensored  (9.6)
9 No Bounds  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 Layers  (9.7)
2 It's More Fun to Com..  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 TRSAC, Gabber & Pebe..  (9.5)
7 Rainbow Connection  (9.5)
8 Dawnfall V1.1  (9.5)
9 Quadrants  (9.5)
10 Daah, Those Acid Pil..  (9.5)
Top Groups
1 Oxyron  (9.3)
2 Booze Design  (9.3)
3 Censor Design  (9.3)
4 Crest  (9.3)
5 Performers  (9.3)
Top Graphicians
1 Sulevi  (9.9)
2 Mirage  (9.8)
3 Mikael  (9.7)
4 Lobo  (9.7)
5 Archmage  (9.7)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.167 sec.