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-18 07:54
WVL

Registered: Mar 2002
Posts: 902
Quote: trash, how does your TAX do X = INT((X*X)/4), then store separate lo/hi byte by the same A value ?

read graham's basic list again :)
2005-10-18 08:26
Trash

Registered: Jan 2002
Posts: 122
Quote: trash, how does your TAX do X = INT((X*X)/4), then store separate lo/hi byte by the same A value ?

Since cbm-basic initializes all variables to zero X=INT((X*X)/4) will always be zero therefore we can use a constant instead...
2005-10-18 08:33
Oswald

Registered: Apr 2002
Posts: 5094
this is not my day
2005-10-18 09:36
WVL

Registered: Mar 2002
Posts: 902
Quote: this is not my day

now guess how Graham feels :)
2005-10-18 11:28
Graham
Account closed

Registered: Dec 2002
Posts: 990
Trash: Basic only initializes when the variable is not already defined. Do X=<whatever> before RUN and constant 0 will not help you :P
2005-10-18 12:15
Bastet

Registered: Jul 2005
Posts: 88
Look closer at that basic listing, Graham...
Does X increase? 'fraid it dosnt, so you can easily assume that x=0 *g*
2005-10-18 12:25
Bastet

Registered: Jul 2005
Posts: 88
That will work out of the box:
1FORX=0TO511:Y=INT((x*x)/4)
2POKE8704+X,INT(y/256):POKE8192+X,Y-(PEEK(8704+x)*256):NEXTX


Thats 80 byte of basic code, tokenized and with header and footer of a standard file. *g*
Runs slow as hell but it works
2005-10-18 12:35
enthusi

Registered: May 2004
Posts: 677
I was indeed considering to try to cut it a bit by using some kernal-mul-routine-call (as not beeing forbidden) but that was about the 54 byte version. 36 is out of the question :(
Too bad. But cudos for this nice fast challenge.
Next time please announce it before everyone else leaves to vacation or something so Im left alone with it for a looong time :)
2005-10-18 13:42
Graham
Account closed

Registered: Dec 2002
Posts: 990
@BastetFurry: Yeps X increases... For example, if you do X=16 before RUN, you'll have 16*16/4 = 64 and then 64*64/4 = 1024 etc.
2005-10-18 15:22
TNT
Account closed

Registered: Oct 2004
Posts: 189
RUN clears all variables. You can circumvent that with GOTO <first_line> tho.
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
SLC
aeeben
Lead/House Designs
CreaMD/React
MWR/Visdom
Guests online: 109
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 Swappers
1 Derbyshire Ram  (10)
2 Jerry  (9.8)
3 Violator  (9.7)
4 Acidchild  (9.7)
5 Cash  (9.6)

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