【问题标题】:LC-3 Code SegmentLC-3 代码段
【发布时间】:2015-03-03 17:16:14
【问题描述】:

我很难理解这个特殊问题。我有答案,但我真的很想知道它们为何如此的原因!我了解每个操作码是如何工作的,只是没有将其应用于这个问题......

一位工程师正在调试她编写的程序。她正在查看程序的以下部分,并决定在内存中的位置 0xA404 处放置一个断点。从 PC = 0xA400 开始,她将所有寄存器初始化为零并运行程序,直到遇到断点。

代码段:

0xA400 THIS1 LEA     R0, THIS1 
0xA401 THIS2 LD      R1, THIS2
0xA402 THIS3 LDI     R2, THIS5
0xA403 THIS4 LDR     R3, R0, #2
0xA404 THIS5 .FILL   xA400

遇到断点时显示寄存器文件的内容(十六进制)。

同样,我不是在寻找答案列表,而是在寻找帮助我了解程序中到底发生了什么的解释。非常感谢!

【问题讨论】:

    标签: lc3


    【解决方案1】:

    如果工程师将断点放在第 0xa404 行(在运行 0xa404 之前停止程序),代码将执行以下操作:

    0xA400 THIS1 LEA     R0, THIS1  ; LEA loads the address of THIS1 into R0.
                                    ; Since THIS1 is at memory location 0xA400, 
                                    ; after this instruction R0 = 0xA400
    
    0xA401 THIS2 LD      R1, THIS2  ; LD loads the contents of the memory at
                                    ; THIS2 into R1.  Since THIS2 is this very
                                    ; line its contents are this instruction,
                                    ; which is 0010001111111111 in binary or
                                    ; 0x23ff in hex, so after this line executes
                                    ; R1 hold 0x23ff
    
    0xA402 THIS3 LDI     R2, THIS5  ; LDI visits THIS5 and treats its value as a
                                    ; new memory location to visit.  It visits 
                                    ; that second location and stores its 
                                    ; contents into R2. In this case, it would
                                    ; look at THIS5 and see its value is 0xA400.
                                    ; It would then visit 0xA400 and store its
                                    ; contents in R2.  0xA400 contains the first 
                                    ; line of your program which translates to
                                    ; 1110000111111111 in binary, 0xe1ff in 
                                    ; hex, so it stores 0xe1ff into R2.
    
    0xA403 THIS4 LDR     R3, R0, #2 ; LDR starts from the memory location of R0,
                                    ; adds 2 to that, then stores whatever it 
                                    ; finds in that memory location into R3. In
                                    ; this case R0 = 0xA400. It adds 2, bringing
                                    ; it up to 0xA402, which is the instruction
                                    ; immediately above this one.  In binary, that
                                    ; instruction is 1010 0100 0000 0001, which
                                    ; translates into 0xa401 so the program stores
                                    ; the program stores 0xa401 into R3.
    
    0xA404 THIS5 .FILL   xA400      
    

    【讨论】:

      猜你喜欢
      • 2015-11-21
      • 2021-08-04
      • 2021-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多