Homework 6 for ECE 109 / CSCI 255

Due date

This assignment is due in class on Thursday, 23 April or to my office assistant in RH 215 by 4:30 pm on 23 April.

Problem 1

Using the techniques presented in class on April 7 and discussed in Chapter 10 of the textbook, translate the following mathematical assignment into LC-3 code using PUSH, POP, OpAdd, and OpMult functions called with the JSR instruction.

   r = (a + b) * (c + d) + e

Assume that a, b, c, d, e, and r have all been defined with .FILL pseudo-instructions for your program.

Your LC-3 code should be about 15 lines long and start with something like the following instructions.

      LD    R2,a
      JSR   PUSH
      LD    R2,b
      JSR   PUSH
      JSR   OpAdd

Problem 2

Assuming that x, y, and z reside at the offsets from R5 given in the following table.

variable offset
x 4
y -3
z 0

Write the four LC-3 instructions needed to execute the following code:

   z = x + y