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 > Mul-table challenge
2005-10-17 13:26
Graham
Account closed

Registered: Dec 2002
Posts: 990
Mul-table challenge

I was just coding another multiplication and once again I had to code a mul-table generator. Somehow I felt like doing it as small as possible and settle this forever. The routine should create:

- function: int((x*x)/4)
- x = 0 to 511
- two tables: 512 low bytes and 512 high bytes
- no dependencies on previous zeropage or register settings

So far I managed to do it in 54 bytes (RTS not included), is anyone able to do a smaller version?

EDIT:

53 bytes now :)
2005-10-17 14:16
Monte Carlos

Registered: Jun 2004
Posts: 359
; (x+1)^2=x^2+(2x+1)
; Always add the next odd number to the prev. square.

lda #<table
sta zptr
lda #>table
sta zptr+1 ;= 8byt

lda #0
sta add
sta add+1
tax
tay ;=8 byt

loop:
clc
adc add
sta (zptr),y
pha
iny
txa
adc add+1
sta (zptr),y
tax
pla
inc add
inc add
bne *+4
inc add+1

iny
bne loop ;= 25 byt
inc zptr+1
ldy zptr+1
cpy #>ende
ldy #0
bcc loop
rts;11 byt

; 8+8+25+11 = ges 52

;Greetings Monte Carlos
2005-10-17 14:16
Monte Carlos

Registered: Jun 2004
Posts: 359
Shit, i forgot the division by 4!!!!
Sorry!
2005-10-17 14:17
Monte Carlos

Registered: Jun 2004
Posts: 359
; (x+1)^2=x^2+(2x+1)
; Always add the next odd number to the prev. square.

lda #<table
sta zptr
lda #>table
sta zptr+1 ;= 8byt

lda #0
sta add
sta add+1
tax
tay ;=8 byt

loop:
clc
adc add
sta (zptr),y
pha
iny
txa
adc add+1
sta (zptr),y
tax
pla
inc add
inc add
bne *+4
inc add+1

iny
bne loop ;= 25 byt
inc zptr+1
ldy zptr+1
cpy #>ende
ldy #0
bcc loop
rts;11 byt

; 8+8+25+11 = ges 52

;Greetings Monte Carlos
2005-10-17 14:20
Monte Carlos

Registered: Jun 2004
Posts: 359
Shit, the post appeared two times!
It was the "back" button of Mozilla, which
caused submitting of an already submitted entry!
Stupid ;)
2005-10-17 14:27
WVL

Registered: Mar 2002
Posts: 902
those are 256 byte tables :)
2005-10-17 14:38
Cruzer

Registered: Dec 2001
Posts: 1048
Graham, just post your code already. 53 bytes sounds good enough for me :)
2005-10-17 14:44
Graham
Account closed

Registered: Dec 2002
Posts: 990
I'll post the code later on. Don't want to destroy new ideas by infecting other peoples brains with my approach :)
2005-10-17 14:51
Oswald

Registered: Apr 2002
Posts: 5094
I have always created those tables in basic..
2005-10-17 15:27
Graham
Account closed

Registered: Dec 2002
Posts: 990
And wasted (1024-x) bytes...
2005-10-17 15:53
tlr

Registered: Sep 2003
Posts: 1790
You didn't say it had to be reentrant or runnable in ROM so I assume selfmod is fine.
My routine is 42 bytes excluding the rts. :)
 
... 41 posts hidden. Click here to view all posts....
 
Previous - 1 | 2 | 3 | 4 | 5 | 6 - 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
Dr.Science/Atlantis
WVL/Xenon
leonofsgr/Singular C..
bexxx
New Design/Excess
Conjuror
ΛΛdZ
Guests online: 144
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 The Demo Coder  (9.6)
6 Edge of Disgrace  (9.6)
7 What Is The Matrix 2  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 No Listen  (9.7)
2 Layers  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 X-Mas Demo 2024  (9.5)
7 Dawnfall V1.1  (9.5)
8 Rainbow Connection  (9.5)
9 Onscreen 5k  (9.5)
10 Morph  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Censor Design  (9.3)
5 Triad  (9.3)
Top Swappers
1 Derbyshire Ram  (10)
2 Jerry  (9.8)
3 Violator  (9.7)
4 Acidchild  (9.7)
5 Cash  (9.6)

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