LC-3: Evaluating (xy')' using only three registers

  • Thread starter Marcin H
  • Start date
In summary, the goal is to calculate xy' using only the three registers. The code would clear R0, move the result from R1 to R0, and bitwise complement R2 to get the result.
  • #1
Marcin H
306
6

Homework Statement


Write a sequence of LC-3 instructions (in bits) to set R0 equal to R1 XOR R2. Assume that values have already been placed into R1 and R2 for you. You may not change the values of any other registers (only R0, R1, and R2). Include RTL or assembly comments explaining the action of each binary instruction. Hints: You MAY change R1 and R2. You should only need eight instructions.

Homework Equations


LC3

The Attempt at a Solution


I came up with X XOR Y = [(xy')' & (x'y)']'

using demorgans, but I can't figure out a way to XOR R1 and R2 using only the 3 registers. R1 and R2 should hold the values to be XOR'd and R0 should store the result. How do I do this?
 
Physics news on Phys.org
  • #2
If you post your attempt it may help those who could assist but who aren't familiar with LC-3 instructions.
 
  • #3
According to Wiki, LC3 is an assembly language for an 16 bit architecture with a 64K address space and eight general purpose registers, R0 through R7. The instruction set is small with only 15 op codes. The only register to register operations are AND, NOT and ADD. The remaining instructions are for loads, stores

It is a load-store architecture. But for our purposes, only the register-to-register instructions (AND, NOT and ADD) are relevant.

There is an opcode for ADD immediate. This takes one register and an immediate literal (specified within the instruction) as input and puts the sum in the designated output register. With a literal #0, this can be used as a register to register move. Similarly, there is an AND immediate which, with a literal #0, could be used as a register clear.

There is an opcode for ADD. This takes one register, ANDs it with a second and leaves the result in the second.

There is an opcode for NOT. This takes one register, bitwise complements it and stores the result in another.

Marcin H said:
I came up with X XOR Y = [(xy')' & (x'y)']'
So the problem at hand is how to evaluate this expression while using only three registers. Can you write code to calculate the left hand term: (xy')', leaving the result in R0 and leaving R1 and R2 intact?
 

1. What is the purpose of setting R0 to R1 XOR R2 in LC-3?

The purpose of setting R0 to R1 XOR R2 in LC-3 is to perform a bitwise exclusive OR operation on the values stored in R1 and R2, and store the result in R0. This operation can be used for various purposes, such as data encryption or error detection.

2. How does the XOR operation work in LC-3?

In LC-3, the XOR operation is performed on binary values. It compares the corresponding bits of two operands, and if they are different, it sets the result to 1. If they are the same, the result is set to 0.

3. Can R0, R1, and R2 be set to any values for the XOR operation in LC-3?

Yes, R0, R1, and R2 can be set to any values in LC-3. The XOR operation will be performed on the values stored in R1 and R2, and the result will be stored in R0.

4. What happens if R1 and R2 have different sizes in LC-3?

If R1 and R2 have different sizes in LC-3, the XOR operation will still be performed. However, the result will be truncated or padded to fit the size of R0.

5. How is the XOR operation used in programming with LC-3?

The XOR operation can be used in programming with LC-3 for various purposes, such as data manipulation, encryption, or error detection. It is often used in conjunction with other bitwise operations to perform complex calculations and logic.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
10
Views
9K
  • Special and General Relativity
Replies
13
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
5K
Replies
4
Views
1K
  • Programming and Computer Science
Replies
3
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
  • Special and General Relativity
Replies
7
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
11
Views
3K
Back
Top