Search code examples
assemblymachine-code

Why do I see R3 register in the LC-3 simulator instead of R1, as I wrote in a sample.bin file?


Program code below:

1110 001 011111111 ; R1 <-- x3100 (PC+0xFF)
0101 011 011100000 ; R3 <-- 0
0101 010 010100000 ; R2 <-- 0
0001 010 010101100 ; R2 <-- 12
0000 010 000000101 ; if Z, goto x300A (PC+5)
0110 100 001000000 ; Load next value to R4
0001 011 011000100 ; Add to R3
0001 001 001100001 ; Increment R1 (pointer)
0001 010 010111111 ; Decrement R2 (counter)
0000 111 111111010 ; Goto x3004 (PC-6)

There is a screenshot that shows the problem I have. enter image description here


Solution

  • If you are using Raw Mode, with the LC-3 simulator, the first line tells it where to locate the subsequent code.  Thus, your 0xE2FF — which you intended as an instruction — is taken as the ORG address, and the first instruction placed there is the first AND instruction (your 2nd intended instruction).

    Try inserting the following as the very first line:

    0000 000 000000000 ; ORG 0x0000
    

    Or use

    0011 000 000000000 ; ORG 0x3000