Symbol Constant Bug

hippy

Ex-Staff (retired)
4.1.14, target PICAXE-08

Has something changed in the way symbol constants are calculated or handled ? It used to be possible to use 32-bit intermediate constants, but that doesn't seem to be working any more ...

- SYMBOL X = 120
- SYMBOL TEN = 10
- SYMBOL X_TIMES_1000 = X * 1000
- SYMBOL RESULT = X_TIMES_1000 / TEN
- PAUSE 5000
- SEROUT 0,N2400,("RESULT=",#RESULT,CR,LF)

That should print "12000" but instead prints "5446" - That seems to be as a result of X*1000 being truncated to 16-bits.
 

hippy

Ex-Staff (retired)
I base my claim that it does handle 32-bit constants on the code I gave at ...

http://www.rev-ed.co.uk/picaxe/forum/Topic.asp?whichpage=2&pagesize=15&topic_id=2504

-SYMBOL K = 3600000
-SYMBOL K_MSW = K / $10000
-SYMBOL K_LSW = K AND $FFFF
-
- w0 = K_MSW
- w1 = K_LSW

3600000 is $36EE80, after execution ...

w0 = $36 , w1 = $EE80 which is correct.

I decided to try some other numbers ...

K = $0001D4C0 : w0 = $0001 , w1 = $D4C0 ok
K = $00123456 : w0 = $0012 , w1 = $3456 ok
K = $12345678 : w0 = $1234 , w1 = $5678 ok
K = $11110000 : w0 = $1111 , w1 = $0000 ok
k = $40000000 : w0 = $4000 , w1 = $0000 ok

That shows 32-bits are being handled correctly. It all goes wrong with K >= $8000000 but that's not unexpected.

I tried some more tests ...

K = $12340000 + $12345678 -> $2468 $5678 ok
K = $12345678 - $11111111 -> $0123 $4567 ok
K = $12345678 / $00000002 -> $091A $2B3C ok
K = $12345678 * $00000002 -> $0000 $ACF0 MSB wrong
K = $00001234 * $00010000 -> $0000 $0000 MSB wrong

Is it correct to say the compiler does handle 32-bit constants but multiply truncates to 16-bits ?

It would be nice to have multiply produce 32-bit results, but please, please, please do not take away existing functionality to enforce 16-bit constants with truncation of intermediate values. Being able to provide 32-bit constants and split them into 16-bit constituent parts is extremely useful as in that drag-strip timer example, and a change would break existing code. I can live with the current situation now I know where my code was going wrong.

Edited by - hippy on 12/28/2005 3:49:01 PM
 
Top