Docsity

Stray Pieces - Machine Structures - Exams, Exams of Structural Analysis

Toggle sidebar
bg1
Computer Science 61C
Midterm 1 - Fall 1995
Professor Harvey, B
Your Name_____________________________________
login cs61c-___
Discussion section number ____
TA's name _____________________________________
This exam is worth 25 points, or 18.7% of your total course grade. The exam contains eight substantive
questions, plus the following:
Question 0 (1 point): Fill out this front page correctly and put your name and login correctly at the top of
each of the following pages.
This booklet contains six numbered pages including the cover page. Put all answers on these pages, please;
don't hand in stray pieces of paper. This is an open book exam.
Page 1
Question 1 (2 points):
(a) Convert 0xca50 to binary.
(b) Convert the value 0xfff7 to decimal, interpteting it as a signed 16-bit integer.
Question 2 (2 points):
Give an example of two four-bit twos-complement integers such that adding them produces a carry out of the
leftmost bit, but not an overflow.
Question 3 (3 points):
Why des the R format use two separate six-bit fields (pocode and function) to specify the operation, instead of
a single 12-bit field?
Question 4 (3 points):
The MIPS instruction BLTZ and BGEZ both have opcode 1; they are distinguished by the RT field, which is
0 for BLTZ and 1 for BGEZ. Why is the RT field used to specify the instruction instead of the funciton field
as usual?
Page 2
Question 5 (4 points):
Given the following C definitions:
CS 61C - Midterm 1 (Fall 95)
Midterm 1 - Fall 1995 1
pf3

Partial preview of the text

Download Stray Pieces - Machine Structures - Exams and more Exams Structural Analysis in PDF only on Docsity!

Computer Science 61C

Midterm 1 - Fall 1995

Professor Harvey, B

Your Name_____________________________________

login cs61c-___

Discussion section number ____

TA's name _____________________________________

This exam is worth 25 points, or 18.7% of your total course grade. The exam contains eight substantive questions, plus the following:

Question 0 (1 point): Fill out this front page correctly and put your name and login correctly at the top of each of the following pages.

This booklet contains six numbered pages including the cover page. Put all answers on these pages, please; don't hand in stray pieces of paper. This is an open book exam.

Page 1

Question 1 (2 points): (a) Convert 0xca50 to binary.

(b) Convert the value 0xfff7 to decimal, interpteting it as a signed 16-bit integer.

Question 2 (2 points): Give an example of two four-bit twos-complement integers such that adding them produces a carry out of the leftmost bit, but not an overflow.

Question 3 (3 points): Why des the R format use two separate six-bit fields (pocode and function) to specify the operation, instead of a single 12-bit field?

Question 4 (3 points): The MIPS instruction BLTZ and BGEZ both have opcode 1; they are distinguished by the RT field, which is 0 for BLTZ and 1 for BGEZ. Why is the RT field used to specify the instruction instead of the funciton field as usual?

Page 2

Question 5 (4 points):

Given the following C definitions:

Midterm 1 - Fall 1995 1

struct thing { char th_type; union { char *thu_symbol; int thu_number; struct {struct thing *thup_car, *thup_cdr;} thu_pair; struct {int thuf_argcount; struct thing (thuf_funct)();} thu_prim; struct {int thuv_size; struct thing ** thuv_array;} thu_vector; } th_union; };

#define th_size th_union.thu_vector.thuv_size #define th_array th_union.thu_vector.thuv_array

typedef struct thing *ThingPtr;

Write a procedure CopyVector that takes two arguments, both of which are ThingPtrs that point to vectors of the same size. (You may assume that the arguments are correct without testing.) The procedure must copy the elements (t he ThingPtrs in the array) from the second vector to the first.

Page 3

Question 6 (5 points):

Convert the following fragment of a C program to MAL. The program computs the hash function for a string:

int hash, size; char ch, *p;

while (ch= *p++) hash = ((hash <<3) + ch) % size;

Assume that all of the variables are in registers, as follows:

$16 hash $17 size $18 ch $19 p

Page 4

Question 7 (2 points):

Which of the following pictures most closely represents the distribution of floating point numbers on the real number line? (not to scale)

Professor Harvey, B 2