Shop OBEX P1 Docs P2 Docs Learn Events
Math in asm — Parallax Forums

Math in asm

KyeKye Posts: 2,200
edited 2008-12-18 19:46 in Propeller 1
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
                        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

  • JCeeJCee Posts: 36
    edited 2008-12-18 05:18
    Have you tried using the CMPS command, it will tell you which value is larger and you can use the Z&C flags to control the subsequent sum
  • AleAle Posts: 2,363
    edited 2008-12-18 19:46
    The instructions that finish in "S" (adds, subs, cmps and so on) are all for 32 bit signed numbers (with sign at bit 31) are the ones to use.
    Some more info about MATH can be found here:
    propeller.wikispaces.org/MATH
Sign In or Register to comment.