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

  • Thread starter Thread starter Marcin H
  • Start date Start date
Click For Summary
SUMMARY

The discussion focuses on implementing the XOR operation between two registers, R1 and R2, in the LC-3 assembly language while only utilizing three registers: R0, R1, and R2. The challenge is to achieve this using a maximum of eight instructions without altering the values in R1 and R2. Key instructions relevant to this task include AND, NOT, and ADD, which are the only register-to-register operations available in the LC-3 instruction set. The solution involves applying De Morgan's theorem to derive the XOR operation using these limited instructions.

PREREQUISITES
  • Understanding of LC-3 assembly language and its instruction set
  • Familiarity with binary operations, specifically XOR
  • Knowledge of De Morgan's laws in boolean algebra
  • Experience with register manipulation in a load-store architecture
NEXT STEPS
  • Research LC-3 assembly language syntax and instruction set
  • Learn how to implement boolean operations using LC-3 instructions
  • Study examples of register manipulation in LC-3
  • Explore advanced techniques for optimizing assembly code in LC-3
USEFUL FOR

This discussion is beneficial for students and developers working with LC-3 assembly language, particularly those tackling problems involving register manipulation and boolean operations.

Marcin H
Messages
306
Reaction score
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
If you post your attempt it may help those who could assist but who aren't familiar with LC-3 instructions.
 
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?
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
10
Views
10K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
11
Views
4K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 4 ·
Replies
4
Views
3K