Shop OBEX P1 Docs P2 Docs Learn Events
Method for writing C/Z flags for SETPAT? — Parallax Forums

Method for writing C/Z flags for SETPAT?

Hi @ersmith

I was adapting a portion of your autobaud code in SimpleSerial.spin for another project and as a novice PASM(2) programmer, I came across something I didn't immediately understand:

autobaud
        dirl    #rx_pin
        waitx   ##1000
        mov mask, ##(1<<(rx_pin-32))
        mov port, #1

            test port, #1 wc    ' set C to distinguish INA/OUTA
            test port, #2 wz    ' set Z (match on =)

        mov waitbit, #0
        mov abcount, #2

Is the second test instruction being used here just as a means of setting the Z flag for setpat? It seems like it only because port is hardcoded to #1 right above it so could never actually be 2 as it's tested for.

This isn't criticism or anything :) just a P2ASM newb wondering if I understand it correctly (I at first even left the test instructions out of the copy of the code completely, not realizing setpat needs the C/Z flags set properly).

Thanks!

Comments

  • AribaAriba Posts: 2,690

    Yes this sets both the C and the Z flag for the setpat instruction.
    I think this is modified from a version which lets you set the port A or B. Optimized you can set both flags in 1 instruction:

             modcz _SET,_SET  wcz
    

    Andy

  • Ah, okay, I was checking earlier to see if there was an instruction dedicated to modifying the flags directly and for some reason, I remembered the wrc/wrz instructions, but found those do the opposite, i.e. write the flags into a register.
    I wasn't aware of modcz, thanks!

    Jesse

  • ersmithersmith Posts: 6,068

    @avsa242 : I don't remember writing that code -- in fact, I can't even find it on my hard disk now! Most likely I cut and pasted it from somewhere else, and then adapted it to the particular situation (which is why port may now be constant when it didn't used to be. In any case I wouldn't hold that code up as any kind of examplar of good coding practices, it's probably kind of hacky.

Sign In or Register to comment.