Shop OBEX P1 Docs P2 Docs Learn Events
Using ASM cribbed from NV143 -- C vs. /C -- also pin connection question — Parallax Forums

Using ASM cribbed from NV143 -- C vs. /C -- also pin connection question

ZootZoot Posts: 2,227
edited 2007-10-22 20:54 in General Discussion
I've been writing some of my first ASM ISRs thanks to the recent articles in Nuts/Volts and from posts at these forums. Having great success. Kudos all around.

A few things I either am not sure of, or can't find in the SX Key manual (but they're probably there).

- in the serial comm ASM code in NV143 (Jon W. cribbed from Al W., I think?), there are these lines:
MOVB C, RX ' sample serial input
TEST rxCount ' receiving now?

So C is...what? The system carry bit? Is moving the bit from the pin there a fast way of subsequently testing for zero? Are the code aliases to the status register(s) register in the manual?

And then later in the same program (code here by Jon, I believe) there i:
SUB svoFrame_LSB, #1 ' DEC svoFrame
SUBB svoFrame_MSB, /C

I get what's happening -- subtract 1 from the lower byte, and if there's a rollover (carry) then subtract that bit value (1 if carry, 0 if not) from the highbyte. But why the slash first on the C?

- Same article -- Jon's schematic has a 10k resistor between the OSC pins (project uses external 50mhz resonator). Why?

- Ditto -- the unused RTCC input is tied high. Is this necessary? If so, why? Just the good habit on the SX of tying pins high or low (or using internal pullups)?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST

Comments

  • BeanBean Posts: 8,129
    edited 2007-10-22 19:41
    Zoot said...

    - in the serial comm ASM code in NV143 (Jon W. cribbed from Al W., I think?), there are these lines:
    MOVB C, RX ' sample serial input
    TEST rxCount ' receiving now?

    So C is...what? The system carry bit? Is moving the bit from the pin there a fast way of subsequently testing for zero? Are the code aliases to the status register(s) register in the manual?


    Yes, C is the carry flag

    And then later in the same program (code here by Jon, I believe) there i:
    SUB svoFrame_LSB, #1 ' DEC svoFrame
    SUBB svoFrame_MSB, /C

    I get what's happening -- subtract 1 from the lower byte, and if there's a rollover (carry) then subtract that bit value (1 if carry, 0 if not) from the highbyte. But why the slash first on the C?


    The slash means Not C, so if C is zero one is subtracted. If C is one, nothing is subtracted

    - Same article -- Jon's schematic has a 10k resistor between the OSC pins (project uses external 50mhz resonator). Why?


    It's a good idea to have the resistor. Sometimes it's needed sometimes not. Depends on the resonator.


    - Ditto -- the unused RTCC input is tied high. Is this necessary? If so, why? Just the good habit on the SX of tying pins high or low (or using internal pullups)?
    The RTCC input is a schmitt trigger, but it is a good idea to tie it either high or low.
    Bean


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    My goal is to live forever...Or die trying.
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • Guenther DaubachGuenther Daubach Posts: 1,321
    edited 2007-10-22 19:55
    Zoot,

    you are right,

    MOVB C, RX

    means MOVe Bit from RX (an input port pin) to the system Carry flag, i.e. to STATUS register bit 0.

    BTW, MOVB is a compoind instruction taking four program words, and four clock cycles to execute. When a port pin 7 is used as RX input (e.g. RB.7), the following "tick" does the same job:

    mov w, <<RB

    This moves the left-rotated contents of RB into the W register but also rotates bit 7 of RB onto the C flag, and this instruction only takes one program word, and one clock cycle. Similarly, you can use

    mov w, >>RB

    when RB.0 is used as RX input pin.


    This is actually a 16-bit decrement, i.e. the LSB (least-significant byte) is decremented first, and then the MSB. At first glance,

    DEC svoFrame_LSB

    seems to be the right instuction for decrementing the LSB. Unfortunately, no flag is set when the decremented variable rolls over from 0 to 255, i.e. when it is necessary to decrement the MSB. Therefore,

    SUB svoFrame_LSB, #1

    which also does a decrement. In addition, the carry flag is normally set, but cleared when a roll-over occurs, i.e. when it is necessary to decrement the MSB. To do this,

    SUBB svoFrame_MSB, /C

    is used. This instruction subtracts the inverted carry bit from svoFrame_MSB, i.e. normally, 0 is subtracted (no change), but 1 is subtracted when C is set after a roll-over of the LSB.


    A 10k resistor in parallel with the 50 MHz resonator is recommended to make sure that the oscillator starts on power-on over the full temperature range. To my own experience, the resistor is not always required but this may also depend on the type of resonator you are using.


    It is a good habit to not leave inputs floating. The RTCC input does not have an internal weak pull-up resistor. Therefore, it is a good idea to either tie it to Vdd or Vss when not in use.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Greetings from Germany,

    G
  • ZootZoot Posts: 2,227
    edited 2007-10-22 20:54
    Thanks to both of you. Right after posting I realized that SUBB was multi-instruction mneumonic -- the expanded assembly is more clear on what's going on.

    I found C explanation in the SX Key Manual -- when doing a SUB the carry bit is the inverse of the "borrow". It seems like if the original value is greater than the result value (at 8 bits), then C gets set, which would give the pattern from the manual:
    Somebody said...
    After an addition:
    Set (1) = a carry has occurred
    Clear (0) = no carry has occurred
    After a subtraction:
    Set (1) = no borrow has occurred
    Clear (0) = a borrow has occurred
    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST
Sign In or Register to comment.