PDA

View Full Version : Might be a dumb division question...



kevlar129bp
- 24th July 2013, 21:21
Hello all,

Long time - no post. Hope everyone is well.
Here goes my dumb question:

Word1 VAR WORD
Word2 VAR WORD

Word1 = 1000000/Word2

Can I do that, or is there a method I may be missing?

Thanks all,
Chris

aratti
- 24th July 2013, 23:13
Tray this should work:

Word1= 1000*1000
Word1= Div32 Word2

Word2 cannot be larger then 32768 (2^15)

Cheers

Al.

AvionicsMaster1
- 24th July 2013, 23:24
I don't think so. What if Word2 = 1 your result would be 1000000 which is well beyond 65535 a WORD variable can handle. You'd have to use a PBP LONG and a 18F chip I think.

Someone else already posted a viable solution.

kevlar129bp
- 25th July 2013, 02:23
Thanks guys,

Aratti's math appears like it will do the trick.

Thanks again,
Chris

aratti
- 25th July 2013, 07:45
I don't think so. What if Word2 = 1 your result would be 1000000 which is well beyond 65535 a WORD variable can handle. You'd have to use a PBP LONG and a 18F chip I think.


In such a case you con intercept the condition with an "IF / THEN" instruction, so that you can handle the error.

For instante: If Word2 is less than 16 goto skip. And handle the math in a different way.
Cheers

Al.