

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The cs61c midterm exam from fall 1999. The exam covers various topics such as 64-bit integers, logical operations, assembler, pointers, arrays, and strings. Students are required to answer questions related to adding and multiplying integers, floating-point representation, utilities in compilation, and handling pointers and arrays.
Typology: Exams
1 / 3
This page cannot be seen from the preview
Don't miss anything!


a. Describe the set of numbers that are represented by a 64-bit two's complement integer. b. Add the following 16-bit integers by hand, show binary result and translate it to hexadecimal.
0001011011100101
c. Multiply the following 16-bit unsigned integers by hand, show binary result and translate to hexadecimal
0000000001101111
d. Encode the value 17.25 10 according to the single precision IEEE Floating-Point standard and show its representation in hexadecimal. e. For each of the following utilities, specify what it takes as input and what it produces as output. Describe one key function it performs in this translation.
f. The C character string "UCB" appears in memory. The first character is word aligned on a little endian machine. Given that the ASCII code for 'A' is 65, what binary bit pattern appears in the word.
Write a sequence of no more than six MIPS instruction that extracts bits 17:11 of register $s0 and inserts them into bits 8:2 of register $s1, leaving all the remaining bits of $s1 unchanged. You may use t-registers as temporaries.
Using the opcode and register map tables on page A-54 , assemble the following MIPS instructions into binary. Show the position of each field by drawing a box around the corresponding bit positions.
Address Instruction Instruction 0x400000 addi $a0, $a0, - 0x400004 L0: bne $s1, $t2, L 0x400008 lw $s2, 128($sp) 0x40000c j L 0x400010 L1: subu $v0, $a0, $s
Consider the folloiwng MIPS assemble language routine. (The numbers oin the left are just line numbers to help in your answer.) foo takes two integer arguments. The caller of foo and its callee bar follow the MIPS procedure call conventions. Assume VAR1 has been declared in the .data section with the .word directive.
1 foo: addi $sp, $sp, - 2 sw $s0, 16($sp) 3 sw $s1, 12($sp) 4 la $t0, VAR 5 lw $t0, 0($t0) 6 add $t1, $a1, $a 7 addi $s0, $t1, 10 8 add $s2, $s0, $t 9 add $a0, $0, $s 10 jal bar 11 add $t2, $t1, $v 12 add $s1, $t2, $a 13 add $v0, $0, $s 14 lw $s1, 12($sp) 15 lw $s0, 16($sp) 16 addi $sp, $sp, 20 17 jr $ra
a. List below four bugs that are present in the code b. For each of these bugs, explain in one sentence either (i) why it will definitely cause the program to not work or (ii) under what condition will the program work correctly, in spite of the bug.
Given the following (correct) C declarations.
char foo = 'A', garply[] = "MIPS", bar = 'C'; char *phi = &foo, *beta = phi, *gamma = garply;
In the following, some of the statements are incorrect or illegal; cross out any such bad statements. Show in the spaces provided what the remaining print statements will print when the program is executed.
printf("%c", *beta); printf("%c", phi); printf("%c", *gamma); printf("%s", bar); beta = garply; printf("%c", *(garply + 2)); printf("%s", &garply[1]); garply = phi; printf("%c", *beta);