If interrupted between instructions a, b do some stuff

128 views Asked by At

I am trying to write assembly to detect if the present interrupt happened between two particular instructions.

I think I have it, but it's not easy for me to test, so if someone could verify I would very much appreciate it.

LDR R0, =INSTR_A ;address of first instruction
CMP LR, R0       ;are we ahead of the first?
BLO NOPE
LDR R0, =INSTR_B ;yes, address of second instr
CMP LR, R0       ;are we ahead of second?
{YEP}LO          ;no, so we're between, do {stuff}LO
{MORE STUFF}LO

Does that look right?

My concern is that I should be using LS instead of LO?

2

There are 2 answers

4
sgupta On BEST ANSWER

LR_IRQ is always address+4 of the instruction that was interrupted.

ie:

 0x00 mov r0, #0  <-- First instruction
 0x04 mov r1, #1
 0x08 mov r2, #2  <-- Interrupt occurs here, Address will be 0x0c in LR_irq not 0x08
 0x0c mov r3, #4  <-- Second instruction

I hope you can figure out what's wrong with your code now :)

6
turboscrew On
LDR R0, =INSTR_A ;address of first instruction
CMP LR, R0       ;If LR < R0 (or LR - R0 underflows), set carry
BLO NOPE         ; Branch if carry set (LO = CC)
LDR R0, =INSTR_B ;yes, address of second instr
CMP LR, R0       ;are we ahead of second?
BLO YEP          ;This is what you meant?