| |
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 :) |
|
| |
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
|
| |
Monte Carlos
Registered: Jun 2004 Posts: 359 |
Shit, i forgot the division by 4!!!!
Sorry!
|
| |
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
|
| |
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 ;)
|
| |
WVL
Registered: Mar 2002 Posts: 902 |
those are 256 byte tables :) |
| |
Cruzer
Registered: Dec 2001 Posts: 1048 |
Graham, just post your code already. 53 bytes sounds good enough for me :) |
| |
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 :) |
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
I have always created those tables in basic.. |
| |
Graham Account closed
Registered: Dec 2002 Posts: 990 |
And wasted (1024-x) bytes... |
| |
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 |