| |
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 |
Assuming that that table was the only one. |
| |
Ben Account closed
Registered: Feb 2003 Posts: 163 |
Graham, please hold yourself from posting the answer a couple of days so I can give it a thought.. |
| |
tlr
Registered: Sep 2003 Posts: 1790 |
Quote: 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. :)
Ok, shaved another byte off. 41 bytes excluding rts. |
| |
Graham Account closed
Registered: Dec 2002 Posts: 990 |
42 bytes with 512 entries and not 256? |
| |
tlr
Registered: Sep 2003 Posts: 1790 |
Quote: 42 bytes with 512 entries and not 256?
Yes 512 entries. Shaved another 2 bytes. 39 bytes excluding rts. :) |
| |
Graham Account closed
Registered: Dec 2002 Posts: 990 |
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 |
| |
tlr
Registered: Sep 2003 Posts: 1790 |
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
No, but against a c-program.
Quick and dirty. ;)
Note also that the code is not in zeropage. If I put it there it will be shorter ofcourse, but that would be cheating in this case, no?
int main(int argc, char *argv[])
{
int i;
FILE *fp;
fp=fopen("bin","wb");
fputc(0x00,fp);
fputc(0xc8,fp);
for (i=0; i<512; ++i) {
int a;
a=i*i/4;
fputc((a&0xff),fp);
}
for (i=0; i<512; ++i) {
int a;
a=i*i/4;
fputc(((a>>8)&0xff),fp);
}
fclose(fp);
}
|
| |
Graham Account closed
Registered: Dec 2002 Posts: 990 |
Nopes, no zeropage ofcourse. Hmm 39 bytes is really hard to believe, I managed to do it in 52 bytes now, or 51 if I use LAX #$00 (which is unstable on C128DCR). |
| |
tlr
Registered: Sep 2003 Posts: 1790 |
Quote: Nopes, no zeropage ofcourse. Hmm 39 bytes is really hard to believe, I managed to do it in 52 bytes now, or 51 if I use LAX #$00 (which is unstable on C128DCR).
I use no undocumented opcodes either. Tell me when you want to have a look at it.
We should probably wait a little while more though. There might come someone else with a 30 byte version. ;)
|
| |
Graham Account closed
Registered: Dec 2002 Posts: 990 |
Ok 43 bytes now here... getting closer :) |
Previous - 1 | 2 | 3 | 4 | 5 | 6 - Next |