Math in asm
Kye
Posts: 2,200
Hello,
I've been trying to do some signed math in asm and things are turning out as expected.
Here's the piece of offending code
Basically, this is the counter update code segment for a PS2 mouse driver. Its similar to Chip's code which is.
The idea is that after using the test statement on the _buttons I will know whether a packet of data is negative or positive. With a value between 0 and 255.
I then use the sumnz command which should add the data packet (a byte) to xAxisCounter (a long) if the result of the test determined the packet was positive. If the result of the test determined the packet·is negative I subtract the·packet from the xAxis counter.
I then repeat the same step for the overflow bit which also appears in ps2 mouse data packets...
Now, everything works when the data is positive (or being added atleast)...But when the packet is subtracted the counter does not simply count down. It jump all over the place.
Chip's code segment works fines though. I not quite sure what his code does exactly or what I would need to do.
Any help?
I've been viewing my results using this segment of spin code.
(0 #> (( || XAxis) <# 127))
Because of the ABS I shouldn't have to worry about twos complement problems, right?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
I've been trying to do some signed math in asm and things are turning out as expected.
Here's the piece of offending code
test _buttons, #$10 wz sumnz xAxisCounter, data test _buttons, #$40 wc if_c sumnz xAxisCounter, #$FF wrlong xAxisCounter, xAxisAddress
Basically, this is the counter update code segment for a PS2 mouse driver. Its similar to Chip's code which is.
test _buttons, #$10 wc 'adjust _x muxc data,signext add _x,data signext long $FFFFFF00
The idea is that after using the test statement on the _buttons I will know whether a packet of data is negative or positive. With a value between 0 and 255.
I then use the sumnz command which should add the data packet (a byte) to xAxisCounter (a long) if the result of the test determined the packet was positive. If the result of the test determined the packet·is negative I subtract the·packet from the xAxis counter.
I then repeat the same step for the overflow bit which also appears in ps2 mouse data packets...
Now, everything works when the data is positive (or being added atleast)...But when the packet is subtracted the counter does not simply count down. It jump all over the place.
Chip's code segment works fines though. I not quite sure what his code does exactly or what I would need to do.
Any help?
I've been viewing my results using this segment of spin code.
(0 #> (( || XAxis) <# 127))
Because of the ABS I shouldn't have to worry about twos complement problems, right?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
Comments
Some more info about MATH can be found here:
propeller.wikispaces.org/MATH