EEC70 UC DAVIS MT

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

description

EEC 70 Sample Midterm with Solutions; Fall 2012; Professor Chuah

Transcript of EEC70 UC DAVIS MT

  • 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

    2

    #under .data temp: .word 0 #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; /* The index of fibonacci number we will print */ int current=0; /* The value of the (i)th fibonacci number */ int next=1; /* The value of the (i+1)th fibonacci number */ int twoaway; /* 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

  • Chuah EEC70

    3

    add twoaway,current,next # compute new fib number move current,next # update current fib number move next,twoaway # update the next fib number add i,i,1 # update x b loop # continue is there are more digits in x outahere: puts prompt2 put current

    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.

    .data number: .word 12345 # the input number bigger: .word # the result temp: .word .text __start: 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