Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
 Welcome to our latest new user eightbitswide ! (Registered 2024-12-24) 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 :)
 
... 41 posts hidden. Click here to view all posts....
 
2005-10-17 18:37
tlr

Registered: Sep 2003
Posts: 1790
Sure! I'll post my 37 byte version, we can compare for fun, and someone else may shorten them further. ;)
2005-10-17 18:39
Graham
Account closed

Registered: Dec 2002
Posts: 990
Ok here it is:
ldx #$00
      txa        ; LAX #$00 would save one extra byte.
      .db $c9
lb1:  tya
      adc #$00
ml1:  sta multabhi,x
      tay
      cmp #$40
      txa
      ror
ml9:  adc #$00
      sta ml9+1
      inx
ml0:  sta multablo,x
      bne lb1
      inc ml0+2
      inc ml1+2
      clc        ; Possible to remove this somehow?
      iny
      bne lb1

2005-10-17 18:40
tlr

Registered: Sep 2003
Posts: 1790
My mul-table: 37 bytes (excuding rts)
C000   A9 00      LDA #$00
C002   A8         TAY
C003   AA         TAX
C004   C8         INY
C005   D0 06      BNE $C00D
C007   EE 15 C0   INC $C015
C00A   EE 1A C0   INC $C01A
C00D   18         CLC
C00E   69 00      ADC #$00
C010   90 01      BCC $C013
C012   E8         INX
C013   99 FF C1   STA $C1FF,Y
C016   48         PHA
C017   8A         TXA
C018   99 FF C3   STA $C3FF,Y
C01B   98         TYA
C01C   4A         LSR A
C01D   68         PLA
C01E   B0 E4      BCS $C004
C020   EE 0F C0   INC $C00F
C023   D0 DF      BNE $C004
C025   60         RTS

2005-10-17 18:42
tlr

Registered: Sep 2003
Posts: 1790
Actually they are extremly different! :)

BTW, in my code multablow is $c200, and multabhighi $c400.

Thank you for the excellent competition! :)
2005-10-17 18:48
Graham
Account closed

Registered: Dec 2002
Posts: 990
Yupz, hard competition :) indeed quite different. I thought they'd look quite similar but they don't. Maybe there is a way to save another byte then... Anyway it was a good idea to do this compo, since without you doing the 42-39 byte versions I would not have investigated any more and just assumed that 53 bytes is the limit :)
2005-10-17 19:01
Tch
Account closed

Registered: Sep 2004
Posts: 512
*imitating a crowd going berzerk*
Wohoo...we want more..heehaaaw!!!
2005-10-17 19:23
Scout

Registered: Dec 2002
Posts: 1570
There's a dutch word for all of this: "bitneuken" :)
---
-= Silicon Ltd. =-
http://forum.siliconlimited.com
2005-10-17 19:44
Bastet

Registered: Jul 2005
Posts: 88
You are nuts! ;)
2005-10-17 20:19
Trash

Registered: Jan 2002
Posts: 122
Quote: Ok this is getting interesting :) Did you verify the resulting table against some basic generator?

10 FOR I=0 TO 511
20 X = INT((X*X)/4)
30 XH = INT(X/256)
40 XL = X - (XH*256)
50 POKE 8192+I,XL
60 POKE 8704+I,XH
70 NEXT


I atleast solved that basiclist in 18 bytes...

LDA #0
TAX
STA L, X
STA L + 256, X
STA H, X
STA H + 256, X
INX
BNE * - 13

:-/
2005-10-18 00:11
raven
Account closed

Registered: Jan 2002
Posts: 137
For converting that Basic prog correctly, the winner
is Trash ;)

I'm still stuck at 36 and my vision is getting
fuzzy so time for sleep..
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
krissz
E$G/HF ⭐ 7
Guests online: 80
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 Layers  (9.6)
2 Cubic Dream  (9.6)
3 Party Elk 2  (9.6)
4 Copper Booze  (9.6)
5 X-Mas Demo 2024  (9.5)
6 Dawnfall V1.1  (9.5)
7 Rainbow Connection  (9.5)
8 Onscreen 5k  (9.5)
9 Morph  (9.5)
10 Libertongo  (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.036 sec.