2223sem2 CS2100
2223sem2 CS2100
2023
Question #: 1
The following C program fragment inverts the bits in a uint32_t integer. The
uint32_t datatype is similar to the int16_t datatype in Assignment 1, except that it
is 32-bits long and unsigned. The example below shows what this operation is
supposed to do. For brevity we will use a 16-bit number instead of a 32-bit number
for illustration.
Original: 0b1011 0010 0100 1100
Return from invert: 0b0100 1101 1011 0011
That is, all 0’s are changed to 1’s and all 1’s are changed to 0’s.
Which ONE of the following C statements should be inserted into the space
marked /* MISSING 1*/? (Note: You are not allowed to enter and run the code on
your computer. Doing so constitutes cheating.)
A. return -x;
B. return !x;
C. return x^0b0;
D. return ~x;
E. None of the above options are correct.
Question #: 2
The following C program fragment reverses the bits in a uint32_t integer. The
example below shows how this operation works. Again, for brevity we will show a
16-bit integer instead of 32-bit:
Original: 0b0010 1101 0110 1010
Return from reverse: 0b0101 0110 1011 0100
Which ONE of the following C statements should be inserted into the space
marked /* MISSING 2*/? (Note: You are not allowed to enter and run the code on
your computer. Doing so constitutes cheating.)
Question #: 3
We now call both the earlier invert and reverse functions in a function called “combine”, to produce the
behavior shown below (example this time is in 32-bit):
Which ONE of the following C statements can be inserted into the space marked /*
MISSING 3 */? (Note: You are not allowed to enter and run the code on your
computer. Doing so constitutes cheating.)
A. return !invert(reverse(x));
B. return !reverse(invert(x));
C. return ~invert(reverse(x));
D. return ~reverse(invert(x));
E. None of the above options are correct.
Question #: 4
Consider a 16-bit fixed-point number system, in sign-and-magnitude representation, with 8 bits in the
integer portion (including sign bit) and 8 bits in the fraction portion. Fill in the following blanks with the full
answer. Do not truncate/round-up/round-down your answer to a lesser number of decimal places.
Most positive number that can be represented: 1
Most negative number that can be represented: 2
Smallest positive number that can be represented: 3
1.
2.
3.
Question #: 5
Consider again the same 16-bit fixed point number system, in sign-and-magnitude representation with 8
bits in the integer portion (including sign bit) and 8 bits in the fraction portion. Find the ABSOLUTE
ERROR for representing the numbers 3.625 and 9.151. When representing both numbers, consider
possible rounding of the least significant bit.
The absolute error is defined to be | target value - actual value |. E.g. if 3.625 is actually represented as
3.626 in this number system, then the absolute error is |3.625 - 3.626| =0.001.
Fill in the blanks with the full answer. Do not truncate/round-down/round-up your answer to lesser
number of decimal places.
Absolute error for representing 3.625: 1
Absolute error for representing 9.151: 2
1.
2.
Question #: 6
Given the same 16-bit fixed point number system in sign-and-magnitude representation with 8 bits for the
integer portion (including sign bit) and 8 bits for the fraction portion, what is 0x95B0 in base-10?
0x95B0 is equal to 1
1.
Question #: 7
1.
Question #: 8
What is 1147 – 367 in base-7? (Hint: Think about how you’d subtract two base-10 numbers, and apply
the same idea here)
114 – 36 = 1 in base 7.
7 7
1.
Question #: 9
1.
Question #: 10
What is -19.1015625 in IEEE-754 format? Write your answer in hexadecimal. Use only digits and capital
A to F and do not remove any leading 0 in your answer. So if your answer is 0x134f, enter it as 0000134F
-19.1015625 in IEEE-754 format is 0x 1
1.
Question #: 11
The MIPS code fragment below works on an integer array A whose base address is stored in $s0 and
size (number of elements) of the array in $s1. The first instruction addi $t1, $s0, 0 is at address
0x00400034.
Below is an equivalent code in C. Let the array name be A and the size (number of elements) of
A be size.
int i;
for (i =1; i <size; i++) {
/* MISSING 4 */
}
Which ONE of the following C statements below should be put into the space marked /*
MISSING 4 */?
Question #: 12
The MIPS code fragment below works on an integer array A whose base address is stored in $s0 and
size (number of elements) of the array in $s1. The first instruction addi $t1, $s0, 0 is at address
0x00400034.
When writing hexadecimal always leave out the 0x, and capitalize all letters. E.g. when the
answer is 0x1fcb, fill it in as 1FCB.
Assuming that size is 8 and array A contains the following values: 3, 5, -2, 4, 0, 7, -1, 6 (A[0]=3
and A[7]=6). What is the final value of $t3?
Final value of $t3 in decimal is: 1
For the instruction beq $t0, $s1, Exit, write out its hexadecimal representation: 0x 2
For the instruction sw $t3, 0($t1), write out its hexadecimal representation: 0x 3
For the instruction j Loop, write out its hexadecimal representation: 0x 4
1.
2.
3.
4.
Question #: 13
Consider the MIPS datapath with the values of the registers shown in the table below, where all
values are in hexadecimal. Suppose the instruction sw $a3, -20($s2) at address 10010 is
currently being executed.
What is the value at (1) (output from sign-extend)? Your answer must be in hexadecimal.
A. 0x00000014
B. 0x0000FFEC
C. 0xFFFFFFEB
D. 0xFFFFFFEC
E. None of the above options are correct.
Question #: 14
Consider the MIPS datapath with the values of the registers shown in the table below, where all
values are in hexadecimal. Suppose the instruction sw $a3, -20($s2) at address 10010 is
currently being executed.
A. 0x00000018
B. 0x00000050
C. 0x00000054
D. 0x80000054
E. None of the above options are correct.
Question #: 15
Consider the MIPS datapath with the values of the registers shown in the table below, where all
values are in hexadecimal. Suppose the instruction sw $a3, -20($s2) at address 10010 is
currently being executed.
A. 0x00000064
B. 0x00000068
C. 0x00000100
D. 0x00000104
E. None of the above options are correct.
Question #: 16
Consider the MIPS datapath with the values of the registers shown in the table below, where all
values are in hexadecimal. Suppose the instruction sw $a3, -20($s2) at address 10010 is
currently being executed.
What is the value at (6)? Your answer must be in binary.
A. 0b0000
B. 0b0001
C. 0b0010
D. 0b0110
E. None of the above options are correct.