Shop OBEX P1 Docs P2 Docs Learn Events
PSXM/GD book: NOP and Registers/Program window ? — Parallax Forums

PSXM/GD book: NOP and Registers/Program window ?

PARPAR Posts: 285
edited 2006-01-02 14:43 in General Discussion
[noparse][[/noparse]PSXM/GD = Programming the SX Microcontroller, by Gunther Daubach]

Regarding Pg. 21(bot)-22(top) on adding NOP instructions to slow down the looping:

I notice in the Program section of the Registers debug window that the debugger "steps" differently from what I would have expected. It steps from clrb to the first nop, then directly·to the jmp.

Loop
· clrb rc.7
·· nop
·· nop
·· nop
· setb rc.7
· jmp· Loop

The setb instruction does get executed; it's just that the debugger steps into the first nop, stepping "over" all the other·nops and·beyond the setb instruction to the subsequent jmp. The intended effect of the 3 nops --to delay the looping at that precise point-- also works, so the nops are getting executed (i.e., taking up one cycle each doing nothing) and the setb is causing the LED to change state so it too is obviously being executed.

I'm curious about why the debugger is designed to step in this way, rather than stepping into each nop and into the setb instructions? (E.g., are the 3 nops and the setb somehow bundled into a single 4-cycle-long version of setb that gets executed at the point the first nop is reached?)

PAR

Comments

  • Guenther DaubachGuenther Daubach Posts: 1,321
    edited 2006-01-02 10:15
    PAR,

    this behavior of the debugger is caused by the internal structure of the SX chips which causes that the debugger can't handle NOP instructions correctly. So, it is not possible to set a breakpoint on a NOP instruction, and single-stepping along NOP instructions also causes strange behavior. Actually, single-stepping is like continuously setting a breakpoint on the next instruction, and this is why the debugger seems to run out of sync when you try to step the NOPs. You are right, although the display is mis-leading, the SX executes all the instructions in correct order, and does not skip any of them.

    Instead of the NOP, you might consider using any other single-cycle instruction but keep in mind that all other instructions modify some register contents, or the flags. For example, if you use and w, #$ff instead, this will preserve the contents of w but might change the Z flag, depending on the current contents of w. In the little loop sample code, this does not matter but it might in other contexts.

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

    G
  • Lord SteveLord Steve Posts: 206
    edited 2006-01-02 14:43
    The SX Key IDE recommends "PAGE $" as a NOP.· I like to use that if I'm not doing any complicated program execution requiring that the program bank bits in the STATUS register be different than the high-order bits of PC.
Sign In or Register to comment.