Shop OBEX P1 Docs P2 Docs Learn Events
Question about PASM 'MOV' instruction and 'WC' effect — Parallax Forums

Question about PASM 'MOV' instruction and 'WC' effect

Consider the two following instructions...

mov AAA, #10 WC

mov BBB, #511 WC

The Manual (v1.2) states on page 311:

If the WC effect is specified, the C flag is set to Value’s MSB.

What does this mean for Immediate values? To my mind it is ambiguous. It might mean that bit [8] is copied into the C flag (because immediate values are only 9 bits long). Or else it could mean that the immediate value is implicitly extended to 32 bits and then bit [31] is copied into the C flag. But is that extension signed or unsigned?

After instruction AAA, what is C? I think probably 0.
After instruction BBB, what is C?

When the source is NOT an immediate value this is of course not ambiguous at all.

Comments

  • None of the instructions behave differently when given an immediate. So MOV with immediate always clears C.

  • So MOV with immediate always clears C.

    Only when WC is specified.

    -Phil

  • CabbageCabbage Posts: 37
    edited 2021-07-07 20:12

    Okay, good to know.

    I'm using this to try to reduce the number of instructions that a serial port transmitter uses...

    'expects: ui_ser_byteTX[7..0] to contain the 8-bit byte to send over serial.
    'returns: nothing
    'remarks: ui_ser_byteTX gets clobbered!
    UI_SERIAL_TX
                            'this MOV instruction also forces the C flag to 0 which we'll use as the START BIT...
                            MOV     ui_ser_bitCount, #10   WC '8 data bits + 1 start bit + 1 stop bit
                            'the above WC effect means that the C flag is now 0 (the MSB of #10 is zero)
    
                            'decorate the value by adding a STOP BIT (on the left)...
                            or      ui_ser_byteTX, #$100
    
                            '...and START BIT (on the right) to the value itself...
                            rcl     ui_ser_byteTX, #1 'C flag (0, see MOV above) is rotated into the LSB, acts as START BIT
    
                            'Now ui_ser_bitCount contains: %1_dddddddd_0
                            'and we'll shift them out to the right >>>, at the correct Baud rate...
    
                            'set up the bit timing
                            mov     ui_ser_time, CNT
                            add     ui_ser_time, UI_SER_BIT_TIME
    
                            'now we're all set to transmit the 10 bits
    
    :ui_ser_TXBitLoop
                            rcr     ui_ser_byteTX, #1   WC 'put the bit into the C flag
                            muxc    outa, UI_SER_TX_PIN 'put the bit (in the C flag) on the wire
                            waitcnt ui_ser_time, UI_SER_BIT_TIME
                            djnz    ui_ser_bitCount, #:ui_ser_TXBitLoop
    
    UI_SERIAL_TX_ret        ret
    
    

    ...where "UI_SER_BIT_TIME" is a value that represents the Baud rate.

    Thank you both. :)

  • Also, just FYI, because the manual doesn't tell you about it, MOVS/MOVD/MOVI and JMP(RET) produce the same C value as a CMP would

  • Cluso99Cluso99 Posts: 18,069

    @Cabbage
    If you are trying to reduce instructions, you should use the smart pin uart.

    Also, you can replace
    rcl ui_ser_byteTX, #1 'C flag (0, see MOV above) is rotated into the LSB, acts as START BIT
    with
    shl ui_ser_byteTX, #1 WC '0 is shifted into the LSB, acts as START BIT, C flag =0

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2021-07-07 22:54

    If you are trying to reduce instructions, you should use the smart pin uart.

    It's the P1 he's talking about: no smart pins.

    -Phil

  • Cluso99Cluso99 Posts: 18,069
    edited 2021-07-08 10:55

    :(
    That's what I get for opening tabs with both P1 & P2 threads

  • CabbageCabbage Posts: 37
    edited 2021-07-08 16:32

    I could try clipping off a couple of P2 IO pins and gluing them to the end of the P1. I'm pretty sure that would work.

    edit: nope

    You're right about the SHL instead of the RCL of course. I don't know what I was thinking when I wrote that.
    Perhaps something like "Hmm, I need to shift in a zero from somewhere... but where? Zeroes are so hard to find these days aren't they?"

    im a stupid

Sign In or Register to comment.