Without seeing your code.... I think this is not an issue.
#chip 16f877a
#option explicit
'USART settings
#define USART_BAUD_RATE 9600
#define USART_TX_BLOCKING
dim val1, val2 as Word
dim answer as long
val1=257
val2=257
answer = val1 * val2
HSerPrint answer
My guess, you have not dimensioned to variables. Use #option explicit
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The root cause of this needs to be looked at. Twice in the last few days the use of Str and Str32 was a cause of a user issue. The same root cause as Val and Val32.
The root cause is the compiler being able to handle overloaded functions (not to be confused with overloaded subroutines). Currently Str and Str32 work around the root cause of the issue -as Str handles Byte and Word with Str32 handling Long and then StrInteger handling Integer.
A potential answer is to have the compiler handle overloaded functions where Str will handle all variable types but until then please use the appropiate function.
Anobium
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi All
val1, val2 and answer are dim as long
val1 * val2 = answer
if val1 = 255 and val2 = 255 calculated answer = 65025 'correct
if val1 = 256 and val2 = 256 calculated answer = 0 'incorrect
if val1 = 257 and val2 = 257 calculated answer = 513 'incorrect
if val1 = 258 and val2 = 258 calculated answer = 1028 'incorrect
looks like a carry over issue.
GCB v98.03
18F25k80 also tried with 18F45k80
anyone seen this?
Thanks
Without seeing your code.... I think this is not an issue.
My guess, you have not dimensioned to variables. Use #option explicit
Not sure what i have done wrong?
Is the correct term "casting". So to get a long answer do the following
answer= [long] val1*val2
Otherwise the calculation will be done as word.
changed val1 and val2 too long, still get the same answer.
Use Str32() rather than str().....
Works. Thanks.
I tried your code and got the same result.
same result if you dim val1,val2 as long.
Last edit: stan cartwright 2018-12-03
The root cause of this needs to be looked at. Twice in the last few days the use of Str and Str32 was a cause of a user issue. The same root cause as Val and Val32.
The root cause is the compiler being able to handle overloaded functions (not to be confused with overloaded subroutines). Currently Str and Str32 work around the root cause of the issue -as Str handles Byte and Word with Str32 handling Long and then StrInteger handling Integer.
A potential answer is to have the compiler handle overloaded functions where Str will handle all variable types but until then please use the appropiate function.
Anobium