View previous topic :: View next topic |
Author |
Message |
lor3nzo Guest
|
multiplication bug |
Posted: Thu Nov 13, 2008 5:04 am |
|
|
Hi,
I'm using pcw 4.032 and the instruction
var=var*5
doesn't work, but I have the correct result with
var=var+var+var+var+var.
Why?
Thank you |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Thu Nov 13, 2008 5:09 am |
|
|
Questions:
What type is 'var'?.
What value is in 'var', when you see the problem?.
Have you looked at the 'sticky' thread at the top of the forum, on 'version 4 coments'. 4.032, is 'borderline', on being a useable version. I'd not have expected something as basic as multiplication to actually give a problem - more likely, something else is failing, and being 'seen' as a problem in the multiplication....
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Thu Nov 13, 2008 5:19 am |
|
|
var is a int16 variable.
This instruction doesn't work too
var1=var2*5
the two variable are int16
var1 is 0 and var2 is 6. |
|
![](templates/subSilver/images/spacer.gif) |
lor3nzo Guest
|
|
Posted: Thu Nov 13, 2008 5:23 am |
|
|
I've this problem with a 18F2321.
I reused this portion of code in a project with a 16f648a and everything is alright. |
|
![](templates/subSilver/images/spacer.gif) |
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Thu Nov 13, 2008 5:44 am |
|
|
You are missing a semicolon var1=var2*5; <----
Is this your code ?
Code: |
main()
{
int16 var1, var2;
var2 = 6;
var1 = var2 * 5;
printf("%Lu, %Lu\r\n", var1, var2);
while(true) {}
}
|
?
If not WHAT is your code ?
How are you looking at the values var1 and var 2 ? |
|
![](templates/subSilver/images/spacer.gif) |
lor3nzo Guest
|
|
Posted: Thu Nov 13, 2008 7:26 am |
|
|
That is the code.
I watch variables with debug mode. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Thu Nov 13, 2008 9:26 am |
|
|
I think you will find that your problem is in the debug, rather than the multiplication. I seem to remember some (several) threads running at about the time that the early V4.03x compilers came out, with problems like this. Try a physical output, like Wayne is showing, and I suspect you will find that the values are fine.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
|