Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
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: 5127
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: 1814
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: 1814
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: 1814
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: 1814
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
Holy Moses/Role
Acidchild/Padua
Krill/Plush
Herrera64
The MeatBall
Doc Strange/Atlantis
GuyGavin/HF
Guests online: 136
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Codeboys & Endians  (9.7)
4 Mojo  (9.6)
5 Coma Light 13  (9.6)
6 Edge of Disgrace  (9.6)
7 Signal Carnival  (9.6)
8 Wonderland XIV  (9.5)
9 Uncensored  (9.5)
10 Comaland 100%  (9.5)
Top onefile Demos
1 Nine  (9.7)
2 Layers  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.5)
6 Scan and Spin  (9.5)
7 Onscreen 5k  (9.5)
8 Grey  (9.5)
9 Dawnfall V1.1  (9.5)
10 Rainbow Connection  (9.5)
Top Groups
1 Artline Designs  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Performers  (9.3)
5 Censor Design  (9.3)
Top Organizers
1 Burglar  (9.9)
2 Sixx  (9.8)
3 Tim  (9.7)
4 Irata  (9.7)
5 hedning  (9.7)

Home - Disclaimer
Copyright © No Name 2001-2025
Page generated in: 0.212 sec.