HOME WORK COVER SHEET 

 University of California at Santa Barbara ECE 15B Computer Organization Homework #4 Due at 11:00 pm May 26th, 2011 HOME WORK COVER SHEET Name (Last, First) ______________________________________________________________ Formatting guidelines: 1)
2)
3)
4)
5)
A completed cover sheet must accompany all homework assignments All homework must be stapled. Paper clips, folded corners, etc. are unacceptable. Use only clean‐edged paper. (No spiral binding or ragged edges) All work must be eligible and clearly organized No credit will be given for problems without necessary work Turning‐in homework: 1)
2)
Homework must be handed in by 11:00 pm in homework box on 3rd floor HFH No late homeworks will be accepted Problem 1 (30 points)
The computer architecture used in our class, MIPS, has one of the simpler instruction sets in
existence. However, it is possible to imagine even simpler instruction sets. In this assignment,
you are to consider a hypothetical machine called OISC, for a One Instruction Set Computer. As
its name implies, OISC has only one instruction: subtract and branch if negative, or subleq for
short. The subleq instruction has three operands, each consisting of the address of a word in
memory:
subleq a, b, c
; Mem[a] = Mem[a] - Mem[b]
; if (Mem[a] ≤ 0) goto c
The instruction will subtract the number in memory location b from the number in location a and
place the result back in a, overwriting the previous value. If the result is greater than or equal to
0, the computer will take its next instruction from the memory location just after the current
instruction. If the result is less than 0, the next instruction is taken from memory location c.
OISC has no registers and no instructions other than subleq.
Although it has only one instruction, OISC can imitate many of the operations of more complex
instruction sets by using clever sequences of subleq instructions. For example, here is a program
to copy a number from location a to location b:
start:
subleq
subleq
subleq
subleq
temp,temp,.+1
temp,a,.+1
b,b,.+1
b,temp,.+1
# Sets temp to zero
# Sets temp to -a
# Sets b to zero
# Sets b to -temp, which is a
In the program above, the notation .+1 means “the address after this one,” so that each
instruction in this program goes on to the next in sequence whether or not the result is negative.
We assume temp to be the address of a spare memory word that can be used for temporary
results.
(i) (15 points) Write an OISC program to add a and b, leaving the result in a and leaving b
unmodified.
(ii) (15 points) Write an OISC program to multiply a by b, putting the result in c. Assume that
memory location one contains the number 1. Assume that a and b are greater than 0 and that
it’s OK to modify a or b
( Hint: What does this program compute? )
c = 0; while (b > 0) {b = b – 1; c = c + a;}
Problem 2 (50 points)
To solve these problems you would need to know the basics for floating point arithmetic
operations. Very good information with examples (in addition to the textbook) can be found at
http://pages.cs.wisc.edu/~cs354-1/cs354/karen.notes/flpt.apprec.html
Part A: Consider the following numbers
(a) -1609.5
(b) 938.8125
(c)
1/3
(i) (6 points) Write down binary number representation of these numbers
(ii) (6 points) Convert these numbers to IEEE 754 single precision format using round to
nearest even scheme
(iii) (6 points) Convert these numbers to IEEE 754 double precision format using round to
nearest even scheme
Part B: Consider the following 32-bit data
(a) 0x1148 00F1
(b)
0xFFFF FFFF
(iv) (4 points) Assuming these data represent IEEE 754 single precision numbers convert them
to decimal ones (using scientific notation if needed)
Part C:
(v)
S
(20 points)
EXP
Consider two numbers written in IEEE 754 single precision format
MANTISSA
0 1000 0001 0000 0000 0000 0000 0000 000
0 1000 0000 1111 1111 1111 1111 1111 111
Subtract the second number from the first one using IEEE 754 arithmetic. Here you should
assume that there are round, guard and sticky bits as required by IEEE standard. Show all the
steps for full credit.
Part D:
(vi) (8 points) What is the maximum relative error (i.e. the difference between the sums
obtained by paper and pencil calculation and that performed using IEEE 754 arithmetic divided
by the total sum) which can be accumulated over N additions for IEEE 754 single precision
normal numbers? Naturally assume that the sum is within the maximum range.
Problem 3 (20 points)
(i) (6 points) How many bytes do the following structures require in MIPS?
a) struct point { int x; int y; }
b) struct rectangle { struct point pt1;
struct point pt2; }
c) struct rectangleList { char *name;
struct rectangle rect;
struct rectangleList *next; }
(ii) (6 points) Suppose the following variables are declared in C code
float
myf;
double
*myd;
struct rectangleList mylist[100];
int
distance;
Assuming that int type is 32 bit and that compiler does not align char data what is the value of
distance for:
a) distance = (int) (mylist+5) – (int) mylist;
b) distance = (int) (&myf +1) – (int) &myf;
c) distance = (int) (myd + 2) - (int ) myd ;
(iii) (8 points) Convert the following C function to MIPS assembly code (using only real MIPS
instructions).
void
}
swap (int *a, int *b) {
int temp;
temp = *a;
*a = *b;
*b = temp;
Problem 4 (30 points)
Optimize code (without changing sorting algorithm) for the Problem #2 from Quiz #1 and
compare the execution time of your code, i.e. new formula, with that of the original one given in
the solutions. Hint: try to increment addresses instead of dedicated indexes and reduce the
number of data flow instructions.