I'm working on a program in LC-3 assembly, and I am having an issue with JSR
. Instead of modifying the PC, jumping to the label, and writing the previous PC to R7, it merely continues to the next instruction. Here is the relevant section:
....
NXTNODE LDR R2, R2, #0 ; get next node
BRz DONE ; now that node is loaded in R2, compare the first and last name
AND R6, R6, #0
AND R3, R3, #0
AND R3, R4, #0 ; copy search term pointer to R3
ADD R6, R2, #0 ; copy node pointer to R6
ADD R6, R6, #3 ; point to last name
AND R5, R5, #0
ADD R5, R5, #1 ; init loop counter
OUTP JSR COMPARE ; uses R6 to compare first and last name to search term.
; if they match, continue (R0 = 1). Otherwise, go to NXTNODE.
ADD R0, R0, #-1
BRnp NXTNODE ; no match, don't print
LDR R0, R6, #0 ; there was a match. Load first name to R0
TRAP x22
LEA R0, SPACE
TRAP x22
....
(The indentation is a little messy from the markdown)
COMPARE
is located at a different location, in this line:
COMPARE ST R1, ST1 ; R6 --> current node
The instruction is never moved to the COMPARE
label. The simulator just steps by it, on to the next instruction.
It was working as expected before, but I must've changed something, and I have no idea what that is, or why it isn't working. Any help would be greatly appreciated.
The simulator just steps by it, on to the next instruction.
Just an idea:
Is the code at the COMPARE
label executed?
Or - to ask differently: Do the registers after the JSR
instruction have the values you would expect after returning from the subroutine?
If yes the simulator might step in "step over" mode you might know from high-level languages, too.
In this mode a function (high-level language) or subroutine (assembler) is not stepped but it is executed and the debugger stops when the function or subroutine has finished.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.