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 > Math, multiply without a loop
2009-11-04 14:16
8bitforever
Account closed

Registered: Oct 2009
Posts: 48
Math, multiply without a loop

How do you multiply a value in the range $00-3F stored in a zeropage always with 40 without using a loop ?

Example1:
Zeropage $fa contains #$04.
hex 04x40=100.
So the result will be hex 100.

Example2:
Zeropage $fa contains #$05.
hex 05x40=140.
So the result will be hex 140.

Example3:
Zeropage $fa contains #$20.
hex 20x40=800.
So the result will be hex 800.
2009-11-04 14:21
WVL

Registered: Mar 2002
Posts: 902
Indulge yourself in your coming study of ASL and ROL!
2009-11-04 14:22
SIDWAVE
Account closed

Registered: Apr 2002
Posts: 2238
(deleted)
2009-11-04 14:27
JackAsser

Registered: Jun 2002
Posts: 2014
Quote: How do you multiply a value in the range $00-3F stored in a zeropage always with 40 without using a loop ?

Example1:
Zeropage $fa contains #$04.
hex 04x40=100.
So the result will be hex 100.

Example2:
Zeropage $fa contains #$05.
hex 05x40=140.
So the result will be hex 140.

Example3:
Zeropage $fa contains #$20.
hex 20x40=800.
So the result will be hex 800.


lda #0
sta $fb ;hi-byte of the result
lda $fa ;lo-byte of the result and input
asl
rol $fb ;*$2
asl
rol $fb ;*$4
asl
rol $fb ;*$8
asl
rol $fb ;*$10
asl
rol $fb ;*$20
asl
rol $fb ;*$40

Result can be read from $fa/$fb (lo-byte, hi-byte)
2009-11-04 15:20
8bitforever
Account closed

Registered: Oct 2009
Posts: 48
Thanks JackAsser !
2009-11-04 15:43
Frantic

Registered: Mar 2003
Posts: 1648
Next step is to realize that multiplying with the same number again again is just unnecessary. It is a typical case were you would probably use lookup tables instead. The tables would not take more than $80 bytes anyway.

You will probably end up doing:

ldx $fa ;source value
lda lobytes,x
sta $fa ;target value, lobyte
lda hibytes,x
sta $fb ;target value, hibyte

lobytes:
!byte $xx, $xx... ;appropriate values ($40 of them)

hibytes:
!byte $xx, $xx... ;appropriate values ($40 of them)
2009-11-04 15:53
Rost

Registered: Oct 2004
Posts: 22
Use a table and your value is the hash!
2009-11-04 16:39
Slammer

Registered: Feb 2004
Posts: 416
If you use JackAssers method then consider storing the initial value in the high byte and use ror instead of rol.

$100 -> $80 ->$40

is faster than

$01-> $02 -> $04 -> $08 ->$10 - $20 -> $40
2009-11-04 18:19
8bitforever
Account closed

Registered: Oct 2009
Posts: 48
Thanks for the additional methods.
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
MWR/Visdom
Hexhog
Mike
Mibri/ATL^MSL^PRX
Mihai
ΛΛdZ
t0m3000/hf^boom!^ibx
Jammer
Scrap/Genesis Project
iAN CooG/HVSC
Case/Padua
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 Edge of Disgrace  (9.6)
6 What Is The Matrix 2  (9.6)
7 The Demo Coder  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 No Listen  (9.6)
2 Layers  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
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 Fullscreen Graphicians
1 Joe  (9.7)
2 Sulevi  (9.6)
3 The Sarge  (9.6)
4 Veto  (9.6)
5 Facet  (9.6)

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