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 > Division
2006-02-20 20:40
Wanderer
Account closed

Registered: Apr 2003
Posts: 478
Division


I'd like to ask a question. I'd prefer it not become an "IFFL" thread that is so hopelessly off-topic it may as well be deleted. Just a simple question and a simple answer PLEASE :)

To the ones who remain helpful and mathematical whizes...

I need to do division for a routine I'm working on. The problem is I have to divide by various numbers, not just sets of two.

For example
LDA #$10
ASL
ASL
gives you 16/4 = 4

However I will need to divide divide by different values (eg. 5, 7, 22, etc.).

Is there such a way to load the Accumulator with a value (or X,Y) and divide it by ANY number, say from 1-200, and if so, how?

I'm very rusty on this. I can't remember a lot of the mathematical functions.

Thanks for any serious answers :)
2006-02-20 21:04
Scout

Registered: Dec 2002
Posts: 1570
Tumtidumtidum...

3D projection on the C=64 (or...how do I divide?)

---
-= Silicon Ltd. =-
http://forum.siliconlimited.com

Commodore 64 Scenemusic Podcast
http://8bitmayhem.blogspot.com/
2006-02-20 21:13
Wanderer
Account closed

Registered: Apr 2003
Posts: 478
Well that helps but it doesn't help. First of all, Perff's routine calls upon "logtable" and "exptable" for which I have no clue what values they hold.

Secondly, the math is explained but unless I see it in actual machine code, I am likely unable to convert it. One of my main weaknesses was always math. ROR, ASL, ADC, SBC are one thing but division such as what I'm asking for, eeek....

I think I will try making a table of values for all possible divisions and see how that works. In the meantime if a better solution comes up in this thread, I'll try it :)

p.s. I actually saw that thread when I did a search (cause I wanted to make sure I didn't ask something that was already posted) but was hoping for something easier to understand. I appreciate the reply :)
2006-02-20 21:25
Slartibartfast
Account closed

Registered: Jul 2002
Posts: 230
Custard.
2006-02-20 22:04
trident

Registered: May 2002
Posts: 91
http://www.google.com/search?q=6502+division

:-)
2006-02-20 22:33
Wanderer
Account closed

Registered: Apr 2003
Posts: 478

Thanks for the link. As the dividend is going to be constant (and 8 bits), I think I'll use a table.

There doesn't seem to be any one catch-all method of doing it but I can make a table from BASIC, save it to memory and it will work - plus take very little cycles to do so :)

2006-02-20 23:52
Scout

Registered: Dec 2002
Posts: 1570
Quote:
Thanks for the link. As the dividend is going to be constant (and 8 bits), I think I'll use a table.

There doesn't seem to be any one catch-all method of doing it but I can make a table from BASIC, save it to memory and it will work - plus take very little cycles to do so :)



Btw, ASL shifts the bits to the left => multiplies by 2.
Check your example in your first post =)
2006-02-21 00:03
Wanderer
Account closed

Registered: Apr 2003
Posts: 478
*hangs head in shame*

Correct you are :)

I found this routine originally from Rene van Belzen which does the job nicely. There are a few mods to make, such as division by zero, etc. but it serves the purpose.

LDA #$00
LDX #$08
ASL $03
l0 ROL
CMP $02
BCC s0
SBC $02
s0 ROL $03
DEX
BNE l0
RTS

"$03 contains the dividend, $02 contains the divisor.
After execution $03 contains the integer result."
2006-02-21 10:44
Oswald

Registered: Apr 2002
Posts: 5094
Wanderer, if your dividend is constant you definitly should use a table.
2006-02-21 13:28
Style

Registered: Jun 2004
Posts: 498
Sorry, Im still snarfing into my fruitloops about the 'I dont know what log and exp are' comment :D
2006-02-21 21:39
Honesty

Registered: Jan 2003
Posts: 121
The routine about is bitwise division.

This routine uses lotsa time, but memory wise it´s the shortest coz using no precalc at all.

It is also possible to divide with log function.
But the result is not so exact.

At the moment i try to divide with the 2nd binomic formular anyone tried it?

2006-02-21 21:47
Wanderer
Account closed

Registered: Apr 2003
Posts: 478
I have plenty of raster time though, however just this morning I realized that the routine along with my original idea of using a pre-calculated table would not work for its indended purpose.

I'm going to have to scrap the idea and make something new.

Argh.
2006-02-22 00:12
Oswald

Registered: Apr 2002
Posts: 5094
you can either unrol the div loop posted above, or learn a bit of the exp and div function.
2006-02-22 02:30
Wanderer
Account closed

Registered: Apr 2003
Posts: 478
The division routine works fine, very well in fact.

The problem is with what I need to divide. :(
2006-02-22 07:28
Slartibartfast
Account closed

Registered: Jul 2002
Posts: 230
Quote: The division routine works fine, very well in fact.

The problem is with what I need to divide. :(


Umbilical.
2006-02-22 10:05
Monte Carlos

Registered: Jun 2004
Posts: 359
Make a drawing, which helps you to find the solution.


Monte
2006-02-22 13:43
Wanderer
Account closed

Registered: Apr 2003
Posts: 478
Quote: Make a drawing, which helps you to find the solution.


Monte


Yep I did make a drawing, I always sketch things that I'm having difficulty implementing into code. Then I fall asleep and let the sub-concious take over. It sounds odd but I've woken up many nights with the solution.

I know how to do the routine, I know how to achieve the effect I desire. The problem is that what I want to divide won't allow me to do the effect I desire. It would only allow for half of the screen. It's difficult to explain but it's dependant upon the effect :)

I have come up with a new idearrrrr.
2006-02-22 14:02
Slartibartfast
Account closed

Registered: Jul 2002
Posts: 230
Quote: Yep I did make a drawing, I always sketch things that I'm having difficulty implementing into code. Then I fall asleep and let the sub-concious take over. It sounds odd but I've woken up many nights with the solution.

I know how to do the routine, I know how to achieve the effect I desire. The problem is that what I want to divide won't allow me to do the effect I desire. It would only allow for half of the screen. It's difficult to explain but it's dependant upon the effect :)

I have come up with a new idearrrrr.


Nasibal.
2006-02-22 19:44
Monte Carlos

Registered: Jun 2004
Posts: 359
I know, it's always difficult not to explain too much.
If you don't want to explain your effect, invent something which leads to the same solution and explain it to us ;)

Etnom
2006-02-22 23:09
Slartibartfast
Account closed

Registered: Jul 2002
Posts: 230
Turtle!
2006-02-23 00:02
Wanderer
Account closed

Registered: Apr 2003
Posts: 478
Quote: I know, it's always difficult not to explain too much.
If you don't want to explain your effect, invent something which leads to the same solution and explain it to us ;)

Etnom


Tell you what, I will PM you with the original idea and see what you think. Perhaps I just need another set of eyes and a different person's perspective to see if it is workable :)

2006-02-23 00:11
Slartibartfast
Account closed

Registered: Jul 2002
Posts: 230
Custard?
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
A3/AFL
Mike
Mr SQL
slimeysmine
celticdesign/G★P/M..
iAN CooG/HVSC
Alakran_64
Mibri/ATL^MSL^PRX
pcollins/Quantum
leonofsgr/Singular C..
Guests online: 179
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 No Listen  (9.7)
2 Layers  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 X-Mas Demo 2024  (9.5)
7 Dawnfall V1.1  (9.5)
8 Rainbow Connection  (9.5)
9 Onscreen 5k  (9.5)
10 Morph  (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 Coders
1 Axis  (9.8)
2 Graham  (9.8)
3 Lft  (9.8)
4 Crossbow  (9.8)
5 HCL  (9.8)

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