Hi Kurt,
I can get my head around this… 
- I’ve got 2 variables that are declared as a word (16 bits)
- Both variables contain a value of 1000.
- If I multiply them, the result will overflow the 16 bits (65536)
How can I store this in a long (32 bits) variable?
I tried the following test program but it doesn’t make sense:
[code]sethserial1 H38400
var1 var word
var2 var word
var3 var word
var4 var long
var1 = 10000
var2 = 10000
main:
var3 = var1*var2
hserout 1, "var3 ", dec var3, 13]
hserout 1, "multi ", dec var1*var2, 13]
var4 = var1*var3
hserout 1, "var4 ", dec var4, 13]
pause 1000
goto main[/code]
The output will give:
var3 57600
multi 100000000
var4 576000000
- So it looks like var3 gets an overflow. Don’t know why 57600 though.
- ‘Multi’ shows that the chip is capable of doing the math.
- It looks like the cast from a word to a long isn’t done correctly.
- Also if I change var1 and var2 to longs it doesn’t give the wanted result.
Any idea what is causing this, and how to solve this?
Thanks