0% found this document useful (0 votes)
66 views3 pages

Eec70 Uc Davis MT

This document contains the sample midterm solution for the University of California, Davis course EEC70: Computer Structures and Assembly Language Programming. The midterm contains 7 questions testing understanding of load instructions, base conversions, floating point representation, implementing multiplication using shift and add instructions without loops, and translating a simple C program to print Fibonacci numbers into SAL assembly code.

Uploaded by

Tiffany Lee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views3 pages

Eec70 Uc Davis MT

This document contains the sample midterm solution for the University of California, Davis course EEC70: Computer Structures and Assembly Language Programming. The midterm contains 7 questions testing understanding of load instructions, base conversions, floating point representation, implementing multiplication using shift and add instructions without loops, and translating a simple C program to print Fibonacci numbers into SAL assembly code.

Uploaded by

Tiffany Lee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

UNIVERSITY OF CALIFORNIA, DAVIS

______________________________________________________________________________________

_________________________________

BERKELEY DAVIS IRVINE LOS ANGELES RIVERSIDE SAN DIEGO SAN FRANCISCO
______________________________________________________________________________________

SANTA BARBARA SANTA CRUZ


_________________________________

EEC70: Computer Structures and Assembly Language Programming

Fall 2012

Sample Midterm Solution


1. Load instruction, PC++, decode, load operands, execute, store result
2. The base seven number 64seven is what number in base three?
64seven = 6x7 + 4 = 46ten
The powers of 3 and the corresponding base three digits are:
34 = 81 33 = 27 32 = 9 31 = 3 30 = 1
The computation is:
46/3 = 15 rem 1
15/3 = 5 rem 0
5/3 = 1 rem 2
1/3 = 0 rem 1
1 2 0 1three
3. Convert the decimal number 207.375 into radix 8 representations.
Translate whole part:
207/8 = 25 rem 7
25/8 = 3 rem 1
3/8 = 0 rem 3
=> 317_eight
Translate fractional part: 0.375*8 = 3.0 => 0.3_eight
207.375_ten = 317.3_eight
4. What is the value of the following floating point number: 0x C2a74000
1 10000101 010 0111 0100 0000 0000 0000
Sign =1 => negative number
Exp = 10000101 = 133 => e = 133-127 = 6
Fraction = 1.011
=> 1.010011101 x 2^6 => 1010011.101
83.625
The number is -83.625
5. If the SAL instruction mul is not available. How do you implement the equivalent function
of
mul y, y, 10
that appears in the program on page 3 using a combination of other SAL instructions and
WITHOUT using a loop structure? If you need additional variables, declare them.
Hint: sll and add are two very useful SAL instructions

Chuah

EEC70

#under .data
temp: .word

#under .text
sll temp, y, 3 # equivalent to y*8
sll y, y, 1
# equivalent to y*2
add y, y, temp # y*8 + y*2 = y*(8+2) = y*10
6. Translate the following C program into SAL
/* This probram prints the value of the nth fibonacci number */
int main(void) {
int n;
int current=0;
int next=1;
int twoaway;

/* The index of fibonacci number we will print */


/* The value of the (i)th fibonacci number */
/* The value of the (i+1)th fibonacci number */
/* The value of the (i+2)th fibonacci number */

printf("Which fibonacci number do you want to print?");


scanf("%d", &n);
for (int i=0; i<n; i++) {
twoaway = current+next;
current = next;
next = twoaway;
}
printf("The number is: %d\n", current);
}

.data
prompt1:
prompt2:
n:
current:
next:
twoaway
i:
.text
__start:
loop:

.asciiz "Which fibonacci number do you want to print?"


.asciiz "The number is: "
.word
# fibonacci number index
.word 0
# value of the ith fibonacci number
.word 1
# value of the (i+1)th fibonacci number
.word
# value of the (i+2)th fibonacci number
.word 0
# loop index variable

puts prompt1
get n
bge i,n outahere

# get the index of the desired fibonacci number


# check the loop termination condition
2

Chuah

outahere:

EEC70

add twoaway,current,next
move current,next
move next,twoaway
add i,i,1
b loop
puts prompt2
put current

# compute new fib number


# update current fib number
# update the next fib number
# update x
# continue is there are more digits in x

done

7. Write a SAL program segment that takes an integer at a memory location labeled number,
multiplies the integer by 100ten, and stores the result at a memory location labeled bigger. For
this program you may not use the SAL mul instruction and you may not use a loop (ie, no
branches allowed). Hint: this multiply can be done by executing 5 SAL instructions.
number:
bigger:
temp:
__start:

.data
.word 12345 # the input number
.word # the result
.word
.text
sll bigger,number,6 # 64 times number
sll temp,number,5 # 32 times number
add bigger,bigger,temp # 96 times number
sll temp,number,2 # 4 times number
add bigger,bigger,temp # 100 times number
done

You might also like