Winter ’18 CIS 314 Midterm A Name: SID:
1. [5] What is the decimal value of the byte 0x38, interpreted as an 8-bit unsigned
int Show your work:
2. [5] What is the decimal value the of byte 0x38, interpreted as an 8-bit (signed) int
Show your work:
3. [5] What is the decimal value of the byte 0x83, interpreted as an 8-bit (signed) int?
Show your work:
4. [10] What is the hex value of x >> 4, assuming x is a 32-bit (signed) int with hex
value 0x83838383? Show your work:
5. [15] What is the decimal value of 0xC1540000, interpreted as an IEEE-754 signleprecision
float Show your work:
6. [15] Consider the follow C function:
int is NegativeZero(float f);
Implement the above function such that it will return 1 if f == -0.0f, 0 otherwise. Do
this using only bitwise operators (ands, ors, shifts) and integer equality (==); no
floating-point operations, if statements, or loops. Hint: access the bit representation
of f by casting its address to an unsigned-int pointer (similar to assignment 2), then
test the value at this pointer against the expected IEEE-754 bit representation for
-0.0 as hex. Comment your code:
7. [20] Consider the following IA32 code, resulting from compiling a function int f(int
x, int y):
pushl %ebp
movl %esp, %ebp
movl 8(%ebp), %eax
movl 12(%ebp), %ecx
leal 10(%ecx,%eax,8), %eax
popl %ebp
retl
a. (15) Convert the above code to C. Comment your code:
b. (5) What is returned by f(1, 2)? Show your work:
8. [25] Consider the following C code:
int popCount(unsigned int x) {
int result = 0;
do {
result += x & 0x1;
x >>= 1;
} while (x);
return result;
}
a. (10) The above code counts the number of 1s in the bit representation of x.
Rewrite the code (in C) to use a label and goto statement rather than a loop.
Comment your code:
b. (15) Convert your C code from part A above into IA32, ensuring that register use
is correct with respect to the IA32 register conventions. Comment your code:
版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。