PropBasic: Signed Two's complement?
skynugget
Posts: 172
hi all, I'm trying to get the prop to talk to the roomba. i have it talking great, but i am having trouble reading the WORDS that are signed.
the roomba spits out two bytes per word highbyte first with a dec range of -32768 to 32768
i have come up with the following, but it only gives me the absolute value. does anyone have any ideas how i could make this work?
im using jons tx_dec routing to debug the output to the terminal. ive attached the rest of my code. thanks in advance!
the roomba spits out two bytes per word highbyte first with a dec range of -32768 to 32768
i have come up with the following, but it only gives me the absolute value. does anyone have any ideas how i could make this work?
RDBYTE rooBuffer(12), vDist vDist = vDist << 8 RDBYTE rooBuffer(13), temp vDist = vDist | temp
im using jons tx_dec routing to debug the output to the terminal. ive attached the rest of my code. thanks in advance!
Comments
You can replace it with: but there is better alternative: This does the sign extend while reading the first byte
Andy
i tried both of those solutions before to no avail. either with the pasm instruction, or starting off with RDSBYTE results in absolute value.
If I use RDSBYTE I get extra code added which deals with sign-extension. Do you mind attaching the generated SPIN code?
Possibly, what values do you get when you display both byte values separately (without sign extension)? Preferably for a negative word.
RDBYTE rooBuffer(12), vDist, temp
vDist = vDist << 8
vDist = vDist | temp
vDist = vDist << 16
\ SAR vDist,#16
If the bytes would be in the other order you would just use RDSWORD.
Bean
it turns out the code works and im a bone head! thanks everyone!