Assignment 5 Solution




Please submit individual source files for coding exercises (see naming conventions below) and a single solution document for non-coding exercises (.txt or .pdf only). Your code and answers need to be documented to the point that the graders can understand your thought process. Full credit will not be awarded if sufficient work is not shown.


  1. [50] Write a Y86 program to implement and test the following C code (sigh – yes, this again):


void swap(int *xp, int *yp) {


int t0 = *xp;


int t1 = *yp;


*xp = t1;


*yp = t0;



Follow the register usage conventions outlined in B&O’H section 3.7.3. Use the Y86 examples from class and the textbook as a guide. Name your source file 5-1.ys.


  1. [25] Draw a circuit (using AND, OR, and/or NOT gates) with inputs A, B, C, and D and one output such that the output is on only if A is on and B is off or C is off and D is on (e.g., (A && !B) || (!C && D)). Include your answer in your solutions document.


  1. [25] In our example Y86 programs, such as the Sum function shown in Figure 4.6, we encounter many cases (e.g., lines 12 and 13 and lines 14 and 15) in which we want to add a constant value to a register. This requires first using an irmovl instruction to set a register to the constant, and then an addl instruction to add this value to the destination register. Suppose we want to add a new instruction iaddl with the following format:





This instruction adds the constant value V to register rB. Describe the computa- tions performed to implement this instruction. Use the computations for irmovl and OPl (Figure 4.18) as a guide.


Write your answer in your solutions document.


Zip the source files and solution document (if applicable), name the .zip file <Your Full Name> (e.g.,, and upload the .zip file to Canvas (see Assignments section for submission link).

error: Content is protected !!