Shop OBEX P1 Docs P2 Docs Learn Events
Testing status flags — Parallax Forums

Testing status flags

4x5n4x5n Posts: 745
edited 2011-12-29 16:38 in General Discussion
I've got a bunch of SX micro-controllers and am looking into writing code for a simple first project. There are no sensors that require advance mathematics. I'm going through the instruction set looking for instructions for testing flag states in the status register. In particular I'm interested in the DC flag. However I don't see any test instructions for flags or individual bits in a register. Is there such a command or am I going to have to mask off the bit with an "and" and then act on the zero flag?

Masking off the bit and acting on it wouldn't be the worst thing in the world but I'd rather not if there's an instruction that will do so directly.

Comments

  • ZootZoot Posts: 2,227
    edited 2011-12-27 17:17
    You can use JNB, JB, SB and SNB in assembly. In SX/B you can just use the bit name (and/or byte name and bit position) in an if/then statement. E.G.,
    :doit
    ADD fileRegister, W
    :testdcbit
    SB DC
       MOV W, #0 ' set W to 0 if DC = 0
    SNB DC
       MOV W, #1 ' set W to 1 if DC = 0
    JB DC, :label1
      MOV fileRegister, #$FF
    :label1
    JNB DC, :label2
      MOV fileRegister, #$80
    :label2
    ' alternatively you could always use a byte.bitindex:
    
    JNB fileRegister.7, :label3 ' only jump if bit7 = 0
      MOV fileRegister, #$80
    :label3
    
    
    IF DC = 0 THEN
       ' do some SX/B stuff
    ELSE
      ' do some SX/B stuff
    ENDIF
    

    Obviously some very special status bits have dedicated instructions, e.g., SNC, SC, JC, JNC, SZ, SNZ, JZ, JNZ. But you could still use the same bit tests, e.g.

    JNB Z, :somelabel

    But it's not as efficient.
  • 4x5n4x5n Posts: 745
    edited 2011-12-27 18:07
    Wow, that was fast and exactly what I was looking for. I figured there had to be a single instruction that would be able to check the DC flag! :smile: Looks like I need to spend more time going over the instruction list for the SX!
  • ZootZoot Posts: 2,227
    edited 2011-12-27 20:23
    Well, SNB is a single word instruction and JNB/JB as well as JC/JNC and JZ/JNZ are all two word instructions (test/address), so in the end it works out to be the same, really.

    At least the instruction set just isn't that big :)

    Here is a really useful cheat sheet.
  • 4x5n4x5n Posts: 745
    edited 2011-12-29 16:38
    The only chips I've done any assembly programming on were the old 8bit Intel (8085, z80) and Motorola chips and that was a very long time ago. Now I'm trying to learn to program in Spin, Pasm as well as SX/b and sasm! :smile:

    Trying to keep things straight is more then a slight challenge. On the positive side I'm having a lot of fun. Yes I know I should at least stick with one processor but I got a bunch of SX processors at a price that I couldn't resist. Now all I have to do is come up with ways to use them. :-)
Sign In or Register to comment.