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

add and adds

Christof Eb.Christof Eb. Posts: 1,106
edited 2023-06-08 06:21 in PASM2/Spin2 (P2)

Hi,
some questions about assembler:

  1. I want to add a signed 8-bit in xx into an unsigned 16bit in cPC. (There will be no overflow of the unsigned 16.bit result)
    At the moment I have:
   signx xx,#7
   add cPC,xx

Is this correct?
I don't understand the difference between add and adds? I always thought that 2s complement takes care of everything.

  1. Is there a faster way to set a register value depending from a flag?
   testbn r3,a wz
   if_nz mov b,#1
   if_z mov b,#0

and:

      cmp r2,#1 wz
      mov xx,#0
      if_z mov xx,#1

Thanks for any hints!
Christof

Comments

  • evanhevanh Posts: 15,192

    @"Christof Eb." said:
    I don't understand the difference between add and adds? I always thought that 2s complement takes care of everything.

    Instead of answering that directly - The Propeller's instruction architecture uses instruction groups that use the two flags in different ways. Ie: The meaning of the flags changes depending on which group of instructions you're executing. Whereas other CPUs might rely more on conditional branching via many more flags that are collectively affected by each instruction.

    So, as a general Prop rule, mixing unsigned instructions with signed instructions would be considered buggy.

  • @evanh said:

    @"Christof Eb." said:
    I don't understand the difference between add and adds? I always thought that 2s complement takes care of everything.

    Instead of answering that directly - The Propeller's instruction architecture uses instruction groups that use the two flags in different ways. Ie: The meaning of the flags changes depending on which group of instructions you're executing. Whereas other CPUs might rely more on conditional branching via many more flags that are collectively affected by each instruction.

    So, as a general Prop rule, mixing unsigned instructions with signed instructions would be considered buggy.

    Thank you!
    The version with add works. I now fond my bug at another location. I assume, that the difference between add and adds is only relevant, if you have wc and use the flag.

  • evanhevanh Posts: 15,192
    edited 2023-06-08 08:24

    Correct. ADD and ADDS only differ in the meaning of the Carry flag. And since they don't take a carry as an input then there is only an impact if the carry is written then subsequently used after the ADD or ADDS.

  • evanhevanh Posts: 15,192
    edited 2023-06-08 12:10

    As for the second question, I guess WRC and WRZ would be best bet. Surprisingly, I've just noticed this group of instructions myself.

                    testbn  r3,a   wz
                    wrz     b
    

    There is also RCZL and RCZR. Useful for stacking just the flags.

  • @evanh said:
    As for the second question, I guess WRC and WRZ would be best bet. Surprisingly, I've just noticed this group of instructions myself.

                    testbn  r3,a   wz
                    wrz     b
    

    There is also RCZL and RCZR. Useful for stacking just the flags.

    Thank you!
    Meanwhile I had stumbled over wrz, but not on RCZL.
    Christof

Sign In or Register to comment.