简体   繁体   English

LC-3:JSR不会修改PC

[英]LC-3: JSR does not modify PC

I'm working on a program in LC-3 assembly, and I am having an issue with JSR . 我正在研究LC-3汇编中的程序,而JSR存在问题。 Instead of modifying the PC, jumping to the label, and writing the previous PC to R7, it merely continues to the next instruction. 无需修改PC,跳转到标签并将之前的PC写入R7,它只会继续执行下一条指令。 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在此行中的其他位置:

COMPARE ST  R1, ST1     ; R6 --> current node

The instruction is never moved to the COMPARE label. 该指令永远不会移至COMPARE标签。 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? 是否执行了COMPARE标签上的代码?

Or - to ask differently: Do the registers after the JSR instruction have the values you would expect after returning from the subroutine? 或-提出不同的要求: JSR指令后的寄存器是否具有从子例程返回后所需的值?

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. 在此模式下,函数(高级语言)或子例程(汇编器)不会步进,但会执行,并且当函数或子例程完成时调试器将停止。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM