# XOR in LC3

#### Marcin H

1. 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.

2. Homework Equations
LC3

3. 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?

Related Engineering and Comp Sci Homework Help News on Phys.org

#### NascentOxygen

Mentor
If you post your attempt it may help those who could assist but who aren't familiar with LC-3 instructions.

#### jbriggs444

Homework Helper
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.

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?

"XOR in LC3"

### Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving