Sample problems for midterm exam
Sample problems for midterm exam
Text practice problems 2.1 to 2.15 and 2.30 to 2.37.
Also text practice problems 3.1 to 3.23.
In the following assume the variables a and b are signed integers and that the machine uses
two¡¯s complement representation. Also assume that MAX_INT is the maximum integer,
MIN_INT is the minimum integer, and W is one less than the word length (e.g., W = 31 for 32-bit
integers). Match each of the descriptions on the left with a line of code on the right (write in the
letter). These are worth two points each.
(i) a
_______________
(ii) a & b
_______________
(iii) a * 7
_______________
(iv) a / 4
_______________
a. ((a ^ b) & ~b) | (~(a ^ b) & b)
b. (a 31);
}
foo3:
Fill in your answers here:
pushl %ebp
movl %esp,%ebp
movl 8(%ebp),%eax
shrl $31,%eax
movl %ebp,%esp
popl %ebp
ret
foo1 corresponds to choice_______.
foo2 corresponds to choice_______.
foo3 corresponds to choice_______.
2
Problem 2. (9 points):
Assume we are running code on a 6-bit machine using two¡¯s complement arithmetic for signed integers. A
¡°short¡± integer is encoded using 3 bits. Fill in the empty boxes in the table below. The following definitions
are used in the table:
short sy = -3;
int y = sy;
int x = -17;
unsigned ux = x;
Note: You need not fill in entries marked with ¡°¨C¡±.
Expression
Decimal Representation
Zero
0
¨C
?6
¨C
Binary Representation
01 0010
ux
y
x >> 1
TMax
?TMin
TMin + TMin
Expression
decimal
binary
----------------------------------Zero
|
0
| 00 0000
--|
-6
| 11 1010
--|
18
| 01 0010
ux
|
47
| 10 1111
y
|
-3
| 11 1101
x >> 1
|
-9
| 11 0111
TMax
|
31
| 01 1111
-TMin
|
-32
| 10 0000
TMin+TMin |
0
| 00 0000
-----------------------------------
Page 3 of 10
Problem 3. (8 points):
Consider the following 5-bit floating point representation based on the IEEE floating point format:
? There is a sign bit in the most significant bit.
? The next two bits are the exponent. The exponent bias is 1.
? The last two bits are the significand.
The rules are like those in the IEEE standard (normalized, denormalized, representation of 0, ¡Þ, and NAN).
As described in class, the floating point format encodes numbers in a form:
(?1)s ¡Á m ¡Á 2E
where m is the mantissa and E is the exponent. The table below enumerates the entire non-negative range
for this 5-bit floating point representation. Fill in the blank table entries using the following directions:
E: The integer value of the exponent.
m: The fractional value of the mantissa. Your answer must be expressed as a fraction of the form x/4.
Value: The numeric value represented. Your answer must be expressed as a fraction of the form x/4.
You need not fill in entries marked ¡°¡ª¡±.
Bits
E
m
Value
0 00 00
¡ª
¡ª
0
0 00 01
0
1/4
1/4
0 00 10
0
2/4
2/4
0 00 11
0
3/4
3/4
0 01 00
0
4/4
4/4
0 01 01
0
5/4
5/4
0 01 10
0
6/4
6/4
0 01 11
0
7/4
7/4
0 10 00
1
4/4
8/4
0 10 01
1
5/4
10/4
0 10 10
1
6/4
12/4
0 10 11
1
7/4
14/4
Page 4 of 10
Problem 4. (8 points):
Consider the source code below, where M and N are constants declared with #define.
int mat1[M][N];
int mat2[N][M];
int sum_element(int i, int j)
{
return mat1[i][j] + mat2[i][j];
}
A. Suppose the above code generates the following assembly code:
sum_element:
pushl %ebp
movl %esp,%ebp
movl 8(%ebp),%eax
movl 12(%ebp),%ecx
sall $2,%ecx
leal 0(,%eax,8),%edx
subl %eax,%edx
leal (%eax,%eax,4),%eax
movl mat2(%ecx,%eax,4),%eax
addl mat1(%ecx,%edx,4),%eax
movl %ebp,%esp
popl %ebp
ret
What are the values of M and N?
M = Answer: M=5
N = Answer N=7
Page 5 of 10
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- cs 107 lecture 2 integer representations
- c reference card ansi constants flow of control program
- signed and unsigned integers in c example
- exchange wikileaks
- sample problems for midterm exam
- eecs 213 midterm exam northwestern university
- security coding module integer error you can t count
- understanding integer overflow in c c university of utah
- defensive programming part 1 types conditionals assertions
- bits bytes and integers
Related searches
- algebra problems for 5th grade
- math problems for 7th graders
- printable math problems for adults
- printable math problems for 1st grade
- math story problems for adults
- free printable word problems for 6th grade
- real world problems for kids
- practice problems for significant figures
- online shopping problems for consumer
- free printable math problems for kids
- math word problems for 1st grade
- math problems for 1st graders worksheets