Shop OBEX P1 Docs P2 Docs Learn Events
Set / Clear Flags — Parallax Forums

Set / Clear Flags

JonnyMacJonnyMac Posts: 9,105
edited 2014-04-10 16:30 in Propeller 1
A long time ago there was a thread about setting and clearing the C and Z flags -- can't seem to find it. The thread may have been started by Phil, but I think it was in the old forums because a bookmark I have is broken.

Does anyone have a link or cool PASM tips for setting and clearing the C and Z flags? My immediate need is to clear the C flag; this is what I'm thinking:
xor     $, $                    nr, wc  ' clear c flag

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2014-04-02 08:39
  • JonnyMacJonnyMac Posts: 9,105
    edited 2014-04-02 08:40
    Thanks, Phil!
  • lonesocklonesock Posts: 917
    edited 2014-04-02 09:08
    Using the instructions themselves as data always struck me as very clever, but since I have a hard time parsing what the code is supposed to do I tend to use an automatically-zeroed special register, like (untested...from memory):
    { C=0 Z=0 } cmpsub outb, #1 wc,wz
      { C=1 Z=1 } cmpsub outb, #0 wc,wz
      { C=0 Z=1 } cmp  outb, #0 wc,wz
      { C=1 Z=0 } cmp  outb, #1 wc,wz
    
    Jonathan
  • HydraHackerHydraHacker Posts: 77
    edited 2014-04-10 15:20
    Hi Guys,
    I believe that this code below will save both the Z & C flags and restore them.

    save flags

    muxnz ZC, #2
    muxc ZC, #1

    restore

    sar ZC, #1 wz, wc

    HydraHacker
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2014-04-10 16:19
    save flags

    muxnz ZC, #2
    muxc ZC, #1

    restore

    sar ZC, #1

    Very slick, indeed (but don't forget to wc,wz in the sar).
  • HydraHackerHydraHacker Posts: 77
    edited 2014-04-10 16:30
    Thanks Phil,

    I added the WZ and WC effects, I had it wrote down on my paper but forgot to include it.

    HydraHacker
Sign In or Register to comment.