Shop OBEX P1 Docs P2 Docs Learn Events
waitpne/peq and carry flag — Parallax Forums

waitpne/peq and carry flag

mirrormirror Posts: 322
edited 2007-06-17 17:45 in Propeller 1
The propeller manual states that for waitpne and waitpeq, wether the INA or INB port is read depends on the state of the carry flag. For the P8X32 this doesn't matter, as INA is always read. BUT, if I'm trying to write "future proof" assembly code, then is there a quick method to set/clear the carry flag?

The best I can come up with is two instructions (multiple variations) eg:
· mov t1,#0
· rcr t1,#1 wc
But that effectively turns waitpne and waitpeq into a 13+ clocks instruction on the new Propeller (if it has the same number of clocks).

Can I do better than this?



▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's not all that hard to count the number of grains of sand on the beach. The hardest part is making a start - after that it just takes time.·· Mirror - 15 May 2007

Comments

  • CardboardGuruCardboardGuru Posts: 443
    edited 2007-06-16 07:30
    To set the carry to zero. From the table on pg 351, it looks like these would work:
    'Uses one long, and 4 to 8 clocks
            TJZ 0,#:here wc
    :here
    
    or 
    
    'Uses 4 clocks and sets a register to zero (which could be a useful side effect)
            XOR t1,t1
    
    
    


    Neither are very elegant though.
  • mirrormirror Posts: 322
    edited 2007-06-16 08:55
    I guess you meant
    XOR t1, t1 wc
    But hey, thanks for that, you could also eliminate the side effect by doing
    XOR t1, t1 wc nr

    Now I just need a single instruction way of setting the carry bit.

    You're right though - not very elegant.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    It's not all that hard to count the number of grains of sand on the beach. The hardest part is making a start - after that it just takes time.·· Mirror - 15 May 2007
  • Alex MackinnonAlex Mackinnon Posts: 25
    edited 2007-06-16 09:15
    Other processors I've used simply include psuedo commands in the assembler - so, for instance, I think CLRC and SETC on some of the PICs translate to 'BCF STATUS,0' and 'BSF STATUS,0' - the ouptut code is still inelegant (although if it sets or clears the carry in a single instruction then who cares I guess) but the source is easier to read.
  • CardboardGuruCardboardGuru Posts: 443
    edited 2007-06-16 10:58
    mirror said...

    But hey, thanks for that, you could also eliminate the side effect by doing
    XOR t1, t1 wc nr

    I forgot about the NR option. I've never found a use for it before. Given that, best to make it obvious the operands are irrelevant.
    XOR 0,0 wc,nr

    You could make it
    XOR 0-0, 0-0 wc,nr

    but perhaps it's better to reserve that convention for self modifying code.
    mirror said...

    Now I just need a single instruction way of setting the carry bit.

    EDIT: Perhaps this would this work?
    SUBX 0,0 wc,nr

    Post Edited (CardboardGuru) : 6/16/2007 11:10:01 AM GMT
  • CJCJ Posts: 470
    edited 2007-06-16 11:05
    if you have a TRUE(32bits of all 1) in one of the registers, just use a SUB with WC and NR like so

    :here SUB :here, true wc nr

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Parallax Forums - If you're ready to learn, we're ready to help.
  • JoannaKJoannaK Posts: 44
    edited 2007-06-16 19:01
    How about this? .. Any odd immeduate should be ok, also could replace SHR with SAR or ROL ?

    :here SHR :here, #1 WC NR
  • CJCJ Posts: 470
    edited 2007-06-16 21:38
    clever

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Parallax Forums - If you're ready to learn, we're ready to help.
  • deSilvadeSilva Posts: 2,967
    edited 2007-06-16 21:46
    More brain-gym: How can you transfer C into Z (and vice versa)?
  • mirrormirror Posts: 322
    edited 2007-06-17 07:08
    Gone for half a day - other side of the world - and all these great ideas crawl out of the woodwork. Thanks.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    It's not all that hard to count the number of grains of sand on the beach. The hardest part is making a start - after that it just takes time.·· Mirror - 15 May 2007
  • HarleyHarley Posts: 997
    edited 2007-06-17 14:25
    deSilva said...
    More brain-gym: How can you transfer C into Z (and vice versa)?
    I'm curious why anyone would want to 'confuse' the meaning of the flag bits? deSilva, please explain how one could improve on the meaning of these bits.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Harley Shanko
    h.a.s. designn
  • deSilvadeSilva Posts: 2,967
    edited 2007-06-17 15:16
    Gladly! First there is no specifc "meaning" of the Z and C. They are just two Ffags to be used as very handy boolean-values. The Propeller is one of the very few processors where you indeed have full control over them. What is a Carry? The State of Bit 0? Bit 31? An arithmetic "overflow"? A negative number? Poppycock - it is true and not true smile.gif

    Second it is always useful to investigate the possibilities of a very new processor to the fullest to improve your understanding. Cf. the suggestions above for instructions for setting "C".
  • HarleyHarley Posts: 997
    edited 2007-06-17 16:14
    IMHO, the Propeller manual, pg 368 Conditiions and pg 371 Effects, explains fairly well these flags for Assembly coding.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Harley Shanko
    h.a.s. designn
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-06-17 17:45
    You are both correct, Z and C have special meaning with arithmetic instructions when used with the wc and wz, however with instructions such as MUXZ and MUXC, the Z and C flags obtain a more generalized purpose than holding indications of zero and carry.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
Sign In or Register to comment.