CSci 281
Final Exam
Name:
_____________________________
Monday, May
200 points
In this course we have studied three related layers or virtual machines: The assembly language layer (where we spent most of our time), the architectural layer (in which we talked about register sets, pipelining and the like) and the hardware layer. We begin with the assembly language layer.
I. The assembly language layer
In talking about the assembly language layer we discussed a variety of issues, primarily the implementation of basic data types together with basic data and control structures, and more recently how the assembler works. We begin with the assembler.
A. The assembler
1. (10 pts.) What is a symbol table, and how is it used?
2. (10 pts.) The assembler directives (psuedo-ops) .text, .data, .bss divide a program’s memory space into three distinct chunks. Briefly explain what each is used for. As a part of your explanation say initialization goes on in each area.
3) (10 pts.) Given the following set of code:
lab01: add %r1, %r2, %r3
cmp %r3, %r5
beq lab01;
What is the machine language representation of the last instruction (the beq instruction)? The op code for a branch instruction is 00, cond for a beq instruction is 0001, and the op2 code for an integer condition code branch is 010. Give your answer in both binary and hex.
B. Assembly language programming
Our emphasis in assembly language programming has been on the implementation in assembly language of various language constructs in higher order languages. We look at several of them here.
1.a (15 pts) Write a complete assembly language function translating the following C routine into assembly language:
int
while (a != b)
if (a > b) a = a – b;
else b = b – a;
return a;
}
1.b (15 pts.) Translate the following C function into a complete assembly language subroutine:
int euclidR(int a, int b) {
if (a == b) return a ;
if (a > b) return euclidR(a-b, b);
return euclidR(a, b-a);
}
2. Data
types
2.a (15 pts.) What is the representation of -13 as an integer? What is its representation as a (double precision) floating point number?
integer
Double precision floating point number (first word only)
2.b (5 pts.) What may happen when two very large positive integers are added to each other and why? What condition code bit checks for this?
3. Data
structures
3.a (15 pts.) Suppose that we have int a[10], an array of 10 integers. The address of a is in %i0. Write the code necessary to find the value of the largest item in the array and put it into %g3
3.b (20 pts.) Suppose that we have the following structure for elements in a linked list.
struct StudentRec {
int exam1, exam2
int avg;
struct StudentRec *next;
};
next is the address of the next record in the list (and is 0 (zero) for the end of the list.
Suppose further that %i0 contains the address of the first record in the list (which is not a header record in this exercise), and that the next field of the last record in the list contains a zero. Write the code to work through the list adding together the two exam scores and placing the average into the avg field. Use integer arithmetic, and do not worry about truncation.
3.c (15 pts.) Write a complete assembly language routine which will take two double precision floating point numbers as arguments and which will return the square root of the sum of the squares of the two numbers input (i.e., the subroutine computes the function sqrt(a*a + b*b)). You should not need to write a square root function.
4. Some architectural issues
4.a (15 pts.) Give a brief description of pipelining, how it works, and the problem it solves. As a part of your answer, explain how pipelining drives the instruction length of SPARC instructions?
4.b (20 pts.) Instead of requiring that all inputs and local variables to a subroutine be placed on a stack, the SPARC architecture gives us a collection of register sets. Explain how this works, beginning with the SAVE instruction and ending with the RESTORE instruction. As a part of your answer, explain how the different register sets (%gx, %ix, %lx, %ox) are swapped around, and why it is important to save any global (%gx) registers you are using before entering a subroutine.
5. Digital
Circuitry
5.a (15 pts.) Using only NAND, NOR, and INVERTER gates, construct a circuit with two inputs which implements the XOR function. Recall that the truth table for XOR is
A |
B |
OUT |
0 |
0 |
0 |
0 |
1 |
1 |
1 |
0 |
1 |
1 |
1 |
0 |
5.b (10 pts.) Construct a circuit diagram for a full adder
5.c (10 pts.) Construct a circuit diagram for a D latch.