| |
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.... |
| |
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 :) |
| |
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... |
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
this is not my day |
| |
WVL
Registered: Mar 2002 Posts: 902 |
Quote: this is not my day
now guess how Graham feels :) |
| |
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 |
| |
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* |
| |
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 |
| |
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 :)
|
| |
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. |
| |
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 |