CS代考 CS 213 Spring 2011

Exam 1 Version 2 Solutions
CS 213 Spring 2011

Copyright By PowCoder代写 加微信 powcoder

67 = 0100 0011
-35 = 1101 1101

* reverseBytes – reverse bytes
* Example: reverseBytes(0x12345678) = 0x78563412
* Legal ops: ! ~ & ^ | + << >>
int reverseBytes(int x)
int newbyte0 = (x >> 24) & 0xff;
int newbyte1 = (x >> 8) & 0xff00;
int newbyte2 = (x << 8) & 0xff0000; int newbyte3 = x << 24; return newbyte0 | newbyte1 | newbyte2 | newbyte3; x = 0, y = 1 Bits Value Bits Value 011 000 1 101 010 5 111 000 17 111 010 NaN 110 001 9 000 011 3/32 110 010 9 1/2 110 000 8 1/2 Note: The correct alignment of 16-byte types on 64-bit Linux is 16 bytes. Since the cheat sheet we handed out gave incorrect information, we accepted solutions assuming 8-byte alignment also. aaaXbbbbbbXXXXXX ccccccccXXXXXXXX dddddddddddddddd eeeeeeeeffffXXXX dddddddddddddddd cccccccceeeeeeee ffffbbbbbbaaaXXX int mystery(int (*f)(int, int), int* arr, int c) if(c <= 0) x = arr[0]; for (i = 1; i < c; i++) x = f(x, arr[i]); The instruction places the value of %ebx onto the stack, and it decrements %esp. %ebx is a callee-saved register; since lolwut uses %ebx, its value upon invocation must be saved so it can be restored before returning to the 0xffff0014 ----------- 0x1000 | b | <- Start argument build area here | a | | ret addr| ebp -> | %ebp |
| |
| |
| |
esp -> | |

A[0] A[1] A[2] A[3]
A[4] A[5] A[6] A[7]
A[120] A[121] A[122] A[123]
A[124] A[125] A[126] A[127]

A[0] A[1] | A[120] A[121]
A[2] A[3] | A[122] A[123]
A[124] A[125] | A[4] A[5]
A[126] A[127] | A[6] A[7]

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com