Download Exam 2

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
CIS 300 Quiz 2 Name: ______________
Part 1: Binary Numbers and Arithmetic.
1. Convert the following binary numbers to decimal (signed and unsigned) and hex:
11001
00011110
1110
Convert the following decimal numbers to 8 bit signed binary numbers. If the conversion
overflows write “OVERFLOW” instead of a result.
12
-8
128
63
-128
2. Add the following 8 bit signed binary numbers; indicate any overflows (but still give a result)
11001111
10000000
01110111
+01000001
+10000000
+01110000
3. Perform the following 8 bit signed arithmetic, indicate overflows
11001100 / 8
11110000 * 16
01010101 / 4
4. Convert the following IEEE Floating point number to decimal:
0 01111110 10100000000000000000000
Convert the number -8.5 to IEEE floating point (32 bits)
5. Write a MIPS code sequence which takes an IEEE float in $a0 and places the exponent only,
converted to an integer between -128 and 127, in register $v0. Hint: this is only three
instructions.
6. Write a MIPS code sequence for the following C fragment, assuming x is in $s0:
*x = *(x+1)+2
7. Short answer / True – False
a) If p points to a 64 bit floating point numbers, to increment p you add _______
b) (T / F) If you divide by 2 using a right shift, the result is rounded up if the number is odd.
c) To divide a signed integer by 2 using a right shift, you shift in _______ bits.
d) When you use a lw instruction, the memory address referenced must end in _________
e) (T / F) A “lw” instruction may access any word in the MIPS memory.
f) (T / F) A “j” instruction can jump to any instruction in the MIPS memory
g) If p points to an 8-bit character, a ______ instruction fetches the character from memory.
h) (T / F) A function is free to change the value of $t1 without saving it on the stack
i) (T / F) In C, the expression a[i] is the same as *(a+i)
j) Fast arithmetic on large integers is important today since computers commonly run
___________________________ software.
k) (T / F) Writing large assembly language programs is likely to cause brain damage.
8. Indicate briefly the bugs in these code snippets (all have OBVIOUS bugs – no need to
understand the logic!)
f:
add
lw
jal
jr
$a0, $a1, $a0
$a0, 4($a0)
put_str
$ra
g:
lw
add
addi
addi
bne
$t0, 0($s0)
$s1, $s1, $t0
$s0, $s0, 1
$s2, $s2, -1
$zero, $s2, g
h:
addi
sw
jal
addi
jal
la
jr
$sp,
$ra,
f1
$a0,
f2
$ra,
$ra
$sp, -4
0($s0)
$v1, 1
0($sp)
9. Convert the following C function into MIPS code: the put_str is the same one as in the
homework. Use the standard parameter passing conventions. Use good comments!
int f(char **a, int *b, int c) {
int sum = 0;
int i;
while (c != 0) {
i = *b;
while (i != 0) {
put_str(*a);
sum++;
i--};
b++; a++; c--;
return(sum);