This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Why is Nop added after bis_sr_register instruction



I have seen some codes,

nop is added after bis & written in comments- set breakpoint here.

I also noted that as soon as bis instruction is executed, debugger first goes to next instrucion & then go to ISR.

  • Hi,

    some MSP430 have an hardware bug that could corrupt the SP/PC if there was no NOP after the BIS instruction. This problem is described for example in the CC430 errata as CPU24, CPU25 and CPU26 bug.

  • Aamir Ali said:
    I also noted that as soon as bis instruction is executed, debugger first goes to next instrucion & then go to ISR.

    All MSP instructions that have a target that is a processor register (like SR/R2 for GIE bit) do not require access to the memory bus while the write operation is performed. So this cycle is used to fetch the next instruction.
    If this instruction has a breakpoitn on it, the breakpoint is triggered at the instruciton fetch, not at the instruciton execution (which follows at least one clock cycle later).
    This causes the breakpoint behind an instruction that sets GIE (with pending interrupts) to be hit before the ISR is executed. Same applies for entering LPM. The breakpoint right after the instruction that sets LPM is hit before LPM is entered.
    If you clear GIE, you should also add a NOP after this. As it may happen on some older MSPs (I think this has been fixed on the newer ones) that the isntruciton right behind is fetched and an interrupt is granted at the same time. Causing the isntruciton to be executed first and the interrupt then, which probably isn't the intention of clearing GIE :) However, by clearing GIE a bit earlier before the operation that must be uninterrupted, will make the NOP obsolete in this case - it can well be a useful operation.

    So if you want to set a breakpoint after a bis instruciton that enables GIE or LPM, put a NOP behind it and place a breakpoint on the next, real instruction.This ensures that the breakpoint is hit after LPM has ended and/or the ISR has been executed.

**Attention** This is a public forum