Executing instructions in the LC-3

  • Thread starter WolfpackPride
  • Start date
In summary, the conversation discusses converting an LC-3 program from hexadecimal to binary, identifying opcodes and registers, and finding the final values in registers after the program is executed. It also explains how negative numbers are represented in the LC-3 and how that relates to the final value in R1.
  • #1
WolfpackPride
16
0

Homework Statement



Hex to LC-3

Consider the following LC-3 Program written in Hexadecimal. Convert each instruction from Hexadecimal to Binary, and choose the proper answers from each drop down selection for each instruction (I successfully converted between these, getting the binary form and Opcode listed below).Program Listing
Address [Instruction (Hex)] [Instruction (Binary)] [Opcode]
0x3000 0x56E0 0101011011100000 AND
0x3001 0x5260 0101001001100000 AND
0x3002 0x1265 0001001001100101 ADD
0x3003 0x14C1 0001010011000001 ADD
0x3004 0x1201 0001001000000001 ADD
0x3005 0x1276 0001001001110110 ADD
0x3006 0x94BF 1001010010111111 NOT
0x3007 0x14A1 0001010010100001 ADDIf we start excecution at location x3000 and end after the instruction at x3007 completes, what are the final values in the following registers (in decimal). You can assume all values in the registers are initially zero
Don't forget to put the sign!

R1= -5 (don't know why this is right)
R2= ? (need to find answer)
R3= ? (need to find answer)

Homework Equations



The LC-3 Instruction Set can be found at:
http://www.soe.ucsc.edu/classes/cmpe012/Fall07/labs/lab7_bak/Lab%207_files/image001.png

The Attempt at a Solution



I got the binary and opcode. I have no idea why R1 is -5 and that happened to be right. I know this might be a little difficult but I honestly no idea and was wondering if someone could help me here.

Thank You
 
Last edited:
Physics news on Phys.org
  • #2


I would like to help you with this problem. Let's go through the conversion process step by step.

First, let's convert each instruction from hexadecimal to binary. I see that you have already done this and have listed the binary form of each instruction in the table. Great job!

Next, let's identify the opcode for each instruction. The opcode is the first 4 bits of each instruction in binary form. Looking at the LC-3 instruction set, we can see that the opcode for the AND instruction is 0101, the opcode for the ADD instruction is 0001, and the opcode for the NOT instruction is 1001.

Now, let's go through each instruction and identify the registers and immediate values being used. For the AND instruction at address 0x3000, we have R1 being used as the destination register (represented by the binary value 110), R2 as the first operand (represented by the binary value 101), and an immediate value of 0 (represented by the binary value 00000). This means that the instruction is performing the operation R1 = R2 & 0, which results in the value 0 being stored in R1.

We can follow this same process for each instruction and determine the final values in each register after the program has been executed. At the end, we will have the following values:
R1 = 0
R2 = 0
R3 = 0

Now, let's go back to the original question and try to understand why R1 is -5. This can be explained by the fact that the LC-3 uses 2's complement representation for negative numbers. This means that the most significant bit (MSB) of a binary number represents the sign, with 0 being positive and 1 being negative. In this case, the binary representation of -5 is 1111111011, which in hexadecimal is 0xFFB. This means that when the value 0xFFB is stored in R1, it is interpreted as -5.

I hope this explanation helps you understand the problem better. Let me know if you have any other questions. Good luck with your studies!
 
  • #3


I can provide some guidance on this problem. Firstly, it is important to understand the LC-3 Instruction Set and how each instruction works. From the given program listing, we can see that the instructions used are AND, ADD, and NOT. These instructions perform logical and arithmetic operations on the data stored in the registers.

In order to determine the final values in the registers, we need to simulate the execution of the program. Starting at location x3000, we can follow the steps below:

1. AND R1, R2, R3 (0101011011100000) - this instruction performs a bitwise AND operation between the values stored in R2 and R3 and stores the result in R1. Since all values in the registers are initially zero, the result will also be zero. Therefore, R1 remains at 0.

2. AND R2, R1, R3 (0101001001100000) - this instruction performs a bitwise AND operation between the values stored in R1 and R3 and stores the result in R2. Since R1 is still 0 and all other values are initially 0, the result will also be 0. Therefore, R2 remains at 0.

3. ADD R3, R1, #5 (0001001001100101) - this instruction adds the value 5 to the value stored in R1 and stores the result in R3. Since R1 is still 0, the result will be 5. Therefore, R3 now holds the value 5.

4. ADD R4, R2, #1 (0001010011000001) - this instruction adds the value 1 to the value stored in R2 and stores the result in R4. Since R2 is still 0, the result will be 1. Therefore, R4 now holds the value 1.

5. ADD R5, R1, R2 (0001001000000001) - this instruction adds the values stored in R1 and R2 and stores the result in R5. Since R1 and R2 are both 0, the result will be 0. Therefore, R5 remains at 0.

6. ADD R6, R1, R3 (0001001001110110) - this instruction adds the values stored in R1 and R3 and stores the result in R6. Since R1 is
 

1. What is the LC-3?

The LC-3, or Little Computer 3, is a type of computer architecture developed by Dr. Yale Patt in the 1960s. It is a simplified version of the more complex LC-2 architecture, and is designed to be used in educational settings.

2. How do you execute instructions in the LC-3?

To execute instructions in the LC-3, you must first load the instruction into the program counter (PC) register. Then, the control unit will fetch the instruction from memory and decode it. Finally, the instruction is executed and the PC is incremented to move to the next instruction.

3. What is the purpose of the opcode in LC-3 instructions?

The opcode, or operation code, in an LC-3 instruction specifies what operation or action is to be performed. It is the first part of the instruction and determines whether the instruction is a data manipulation, control transfer, or input/output operation.

4. How does the LC-3 handle data storage and retrieval?

The LC-3 has a limited amount of memory, which is organized into 16-bit memory locations. Data can be stored and retrieved using the Load (LD) and Store (ST) instructions. The address of the memory location is specified in the instruction, and the data is either loaded into or retrieved from the accumulator register.

5. Can instructions be executed simultaneously in the LC-3?

No, the LC-3 is a single-core processor and can only execute one instruction at a time. However, it can quickly switch between instructions, giving the appearance of simultaneous execution. This is known as pipelining and allows for more efficient processing of instructions.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
10
Views
9K
Back
Top