PASM & Multiplication and Division....
Chris_D
Posts: 305
Hi folks,
I have a routine in SPIN that I strongly suspect will run better in PASM.· I have good success converting many tasks to PASM from SPIN but multiplication and division stumped me completely.· I found a few references (wikipedia and Dsilvas texts) on routines but can't make sense of them or how to use them.·
Here is what I am trying to do ....
Var_1 ' can be a value from 0 to 200000
Var_2 ' can be a value from 0 to 10000
Var_3 ' can be a value from 100 to 5000
Var_V := ((Var_1 * Var_1) - (Var_2 * Var_2)) / (2 * Var_3)
The above statement is in SPIN of coure.
From reading through the examples and references, there are limits to the max value for the result so I felt it important to show the ranges of data I am trying to work with.
I suspect this might be a BIG help for all of us PASM newbies if we could get a clear explanation of how to do this.
Thanks in advance
Chris
·
I have a routine in SPIN that I strongly suspect will run better in PASM.· I have good success converting many tasks to PASM from SPIN but multiplication and division stumped me completely.· I found a few references (wikipedia and Dsilvas texts) on routines but can't make sense of them or how to use them.·
Here is what I am trying to do ....
Var_1 ' can be a value from 0 to 200000
Var_2 ' can be a value from 0 to 10000
Var_3 ' can be a value from 100 to 5000
Var_V := ((Var_1 * Var_1) - (Var_2 * Var_2)) / (2 * Var_3)
The above statement is in SPIN of coure.
From reading through the examples and references, there are limits to the max value for the result so I felt it important to show the ranges of data I am trying to work with.
I suspect this might be a BIG help for all of us PASM newbies if we could get a clear explanation of how to do this.
Thanks in advance
Chris
·
Comments
http://forums.parallax.com/showthread.php?p=828096
Leon
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Amateur radio callsign: G1HSM
Suzuki SV1000S motorcycle
Var_1 ^2 is therefore a 36 bit value (overflow!), Var_2 ^2 is a 28 bit value, and 2 * Var_3 is a 14 bit value. So you're going to have a problem in SPIN with overflow. You can probably do it using * and **, but I'm getting a headache trying to work out the code.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Composite NTSC sprite driver: Forum
NTSC & PAL driver templates: ObEx Forum
OnePinTVText driver: ObEx Forum
http://forums.parallax.com/showthread.php?p=711064
And this is how I extracted it...
I thus far haven't had a need for DIV but I know where to go when I do.
Chris
Your code comment says, "32 to 64 bit signed multiply". Does this really do 64 bits? If so perhaps you can provide an example; a little wrapper that makes this an application perhaps? I'm new to PASM.
Thanks, David