CS61C Midterm Exam - Fall 1999, Exams of Structural Analysis

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

2012/2013

Uploaded on 04/02/2013

shalabh_li43y
shalabh_li43y 🇮🇳

4.5

(18)

88 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS61C MIDTERM EXAM
FALL 1999
1. Facts, Figures and Bit [12 points]
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
+0011101001101100
c. Multiply the following 16-bit unsigned integers by hand, show binary result and translate to hexadecimal
0000000001101111
+0000000000001010
d. Encode the value 17.2510 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.
CompilerAssemblerLinkerLoader
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.
2. Logical Operations [5]
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.
3. Assembler/Instruction Format [5]
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, -4
0x400004 L0: bne $s1, $t2, L1
0x400008 lw $s2, 128($sp)
0x40000c j L0
0x400010 L1: subu $v0, $a0, $s0
CS 61C, Midterm, Fall 1999
CS61C MIDTERM EXAM FALL 1999 1
pf3

Partial preview of the text

Download CS61C Midterm Exam - Fall 1999 and more Exams Structural Analysis in PDF only on Docsity!

CS61C MIDTERM EXAM

FALL 1999

1. Facts, Figures and Bit [12 points]

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.

  • Compiler
  • Assembler
  • Linker
  • Loader

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.

2. Logical Operations [5]

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.

3. Assembler/Instruction Format [5]

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

CS61C MIDTERM EXAM FALL 1999 1

4. Correct Assembly Language [8]

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.

5. Pointers, Arrays, and strings [5 points]

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);

  1. Assembler/Instruction Format [5] 2