Shop OBEX P1 Docs P2 Docs Learn Events
CMPS/CMPSX versus SUBS/SUBSX — Parallax Forums

CMPS/CMPSX versus SUBS/SUBSX

ericballericball Posts: 774
edited 2007-08-21 12:50 in Propeller 1
Is there any reason CMPS/CMPSX have·different opcodes than SUBS/SUBX instead of just having R=0?

(I love the Prop's ISA.· JMPRET especially.)
·

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-08-20 23:33
    Compare and subtract on signed quantities are two different operations. The carry flag after a signed compare reflects the value of a signed borrow. After a signed subtract, it represents the value of a signed overflow.

    For example (using eight bits instead of 32),

    ····00000001 (1) compared to
    ····10000000 (-128) yields C = 0, since 1 > -128

    But,

    ····00000001 (1) minus
    ····10000000 (-128) yields 129, which is too big for a signed byte to hold, so C = 1, representing the overflow.

    -Phil
  • ericballericball Posts: 774
    edited 2007-08-21 12:50
    D'oh! Prop only has C & Z flags, and is missing the N & V flags. So really, the difference between SUB/CMP, SUBS, and CMPS are how they set the C flag. The actual result will be the same in all cases, right?
Sign In or Register to comment.