PDA

View Full Version : Word and REV and ~



cmolson
- 1st December 2005, 13:59
Ok i've been up all night playing with this, thanks for helping me with the constant thing (I think i'll move it to eeprom if i have a chance) Anyways now I have another problem here is the code:

Cash and Cost are both Words

hCost is Byte1 of Cost and lCost is byte0


debugin [Temp[0],Temp[1],hCost,lCost] 'Receive 4 Bytes
Cost=~Cost Rev 16 'Invert Cost and rev bits
Cash=~Cash Rev 16 'Invert Cash and rev bits
Cash = Cash - Cost ' Subtract Cost from Cash
Cash=~Cash Rev 16 're invert Cash
debug hCash,lCash 'Send both bytes out serially


This code takes a 4 byte instruction where the last two bytes is a cost which for now is fixed at $00 $FA. All this info is recieved inverted so i need to Not the variable and reverse the bits. The problem I'm having is that lets say I set Cash to be $11C6, when I run this code it outputs $11CC, It gets the last byte correct, $CC however the $11 should be $10. Any ideas?

cmolson
- 1st December 2005, 16:18
I also found something weird... if i use the SWAP command between lCost and hCost:


Swap lCost,hCost

Both variables end up holding the same data $CC.. I still can't figure out why this is happeneing yet. It is like there is a problem writing data to the higher byte in Cost (hCost)

Kamikaze47
- 1st December 2005, 18:22
$11C6 inverted and reversed is $138E
$00FA inverted and reversed is $141F

is you subtract $141F from $138E you get a negative number