Shop OBEX P1 Docs P2 Docs Learn Events
PASM adds and subs — Parallax Forums

PASM adds and subs

Duane DegnDuane Degn Posts: 10,588
edited 2011-10-04 14:18 in Propeller 1
I'm not sure if I understand signed add and subtract.

I want to adjust privateTarget0 up or down based on the change in targetSpeed0.

targetSpeed0 can be positive or negative (so can privateTarget0).

In this portion of the program, I save the earlier targetSpeed0 to previousSpeed0. I use the temporary variable "difference" to calculate, what I think should be, the change in targetSpeed0.

I plan to modify privateTarget0 in a another part of the program so it wont stay equal to targetSpeed0. But for now, the two values should match (or so I think). Both values start at zero. This is the only place targetSpeed0 is changed (by reading value from hub).
updateTarget            mov     previousTargetSpeed0, targetSpeed0
                        rdlong  targetSpeed0,targetAddress0
                        mov     difference, targetSpeed0
                        subs    difference, previousTargetSpeed0   ' has target speed changed?                
                        adds    privateTarget0, difference         ' adjust privateTarget speed to reflect change
 
                        wrlong  privateTarget0, privateTargetAddress0

For now, I'm writing privateTarget0 to hub RAM for debugging. I don't think I'll need access to it in the final version of the program.

When I watch the variables from a different cog I see privateTarget0 increase when targetSpeed0 is increased but privateTarget0 doesn't decrease when targetSpeed0 is decreased.

Is there an error in my understanding of subs and/or adds or is my problem hiding somewhere else?

Thanks,

Duane

Comments

  • Dave HeinDave Hein Posts: 6,347
    edited 2011-10-04 13:31
    The code looks OK to me, so the error must be in some other part of the code. BTW, adds/subs is the same as add/sub, except for how they set the carry flag.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-10-04 14:18
    Thank you Dave. I must have and error where the code checks to see if that subroutine is executed.

    This should help me find the problem.
    Dave Hein wrote: »
    BTW, adds/subs is the same as add/sub, except for how they set the carry flag.

    Thank you for this additional information. I didn't understand the difference between signed and unsigned add and subtract.

    I'm trying to control four motors with encoders from within one cog.

    Duane
Sign In or Register to comment.