| |
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.... |
| |
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
|
| |
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
|
| |
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! :) |
| |
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 :) |
| |
Tch Account closed
Registered: Sep 2004 Posts: 512 |
*imitating a crowd going berzerk*
Wohoo...we want more..heehaaaw!!! |
| |
Scout
Registered: Dec 2002 Posts: 1570 |
There's a dutch word for all of this: "bitneuken" :)
---
-= Silicon Ltd. =-
http://forum.siliconlimited.com |
| |
Bastet
Registered: Jul 2005 Posts: 88 |
You are nuts! ;) |
| |
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
:-/ |
| |
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..
|
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
trash, how does your TAX do X = INT((X*X)/4), then store separate lo/hi byte by the same A value ? |
Previous - 1 | 2 | 3 | 4 | 5 | 6 - Next |