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 16:00
Oswald

Registered: Apr 2002
Posts: 5094
Graham: yeah, so my vector parts load 0.1 second slower, did you notice ? :(
2005-10-17 16:05
Graham
Account closed

Registered: Dec 2002
Posts: 990
Assuming that that table was the only one.
2005-10-17 16:08
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..
2005-10-17 16:12
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.
2005-10-17 16:20
Graham
Account closed

Registered: Dec 2002
Posts: 990
42 bytes with 512 entries and not 256?
2005-10-17 16:23
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. :)
2005-10-17 16:29
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
2005-10-17 16:31
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);
}

2005-10-17 16:47
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).
2005-10-17 16:52
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. ;)
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
No-XS
slimeysmine
psenough
Guests online: 95
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 Graphicians
1 Mirage  (9.8)
2 Archmage  (9.7)
3 Pal  (9.6)
4 Carrion  (9.6)
5 Sulevi  (9.6)

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