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

  • Thread starter Thread starter Marcin H
  • Start date Start date
AI Thread Summary
The discussion focuses on creating a sequence of LC-3 instructions to compute R0 as the XOR of R1 and R2, while only using three registers. Participants highlight the challenge of implementing the XOR operation with limited instructions, given that LC-3 only supports AND, NOT, and ADD for register-to-register operations. The expression X XOR Y is reformulated using De Morgan's laws, but the implementation remains unclear. Key instructions mentioned include using ADD with an immediate value for register moves and NOT for bitwise complements. The goal is to achieve the XOR result in R0 without altering R1 and R2, emphasizing the constraints of the LC-3 architecture.
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?
 
Thread 'Have I solved this structural engineering equation correctly?'
Hi all, I have a structural engineering book from 1979. I am trying to follow it as best as I can. I have come to a formula that calculates the rotations in radians at the rigid joint that requires an iterative procedure. This equation comes in the form of: $$ x_i = \frac {Q_ih_i + Q_{i+1}h_{i+1}}{4K} + \frac {C}{K}x_{i-1} + \frac {C}{K}x_{i+1} $$ Where: ## Q ## is the horizontal storey shear ## h ## is the storey height ## K = (6G_i + C_i + C_{i+1}) ## ## G = \frac {I_g}{h} ## ## C...
Back
Top