Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
CSE30 Practice Questions
Note: these problems are provided AS IS. You should assume that all the material
covered in the class is fair game for the exam (unless we tell you otherwise) and that the
material reflected in these problems is not necessarily an indication of the content of the
FINAL. We also attempted to make error free problems but make no guarantees that
these problems are indeed error free. There are also additional practice problems in the
midterm review discussion slides for practicing earlier content, and practice problems on Single
Cycle Design in the optional homework this week.
Table of Contents
1. Number Systems
2. C Pointers
3. C Memory Management
4. ARM Arithmetic/Control
5. ARM Data Transfer/Procedures/Stack Management
6. Digital Logic
7. ARM Assembly → Machine
Number Systems
1. Convert the following binary numbers into hexadecimal
a. 1111→ 0x__ f
b. 1100→ 0x__ c
c. 1010→ 0x__ a
d. 1110→ 0x__ e
e. 1101→ 0x__ d
f. 1011→ 0x__ b
2. What is the largest 2’s complement number that can be represented in 12 bits. What is
the smallest 2’s complement number that can be represented in 12 bits.
1 bit sign, 2^11 -1 = 2047
1000_0000 = -2048
NOTE: more practice in H&H 1.10, 1.11, 1.12
3. (H&H 1.25) Convert the following base-10 decimal numbers to unsigned binary numbers
a. 42
10_1010
b. 63
11_1111
c. 229
1110_0101
d. 845
11_0100_1101
4. Express -45 base-10 in binary (2’s complement, 8-bits)
0010_1101 -> 1101_0010 + 1 = 1101_0011
5. Convert the following decimal numbers to floating point in binary using IEEE-754 Single
Precision Format
sign (1) exponent (8) mantissa (23)
a. -0.1328125
1011_1110_0000_1000_0000_0000_0000_0000
b. 14.5
0100_0001_0110_1000_0000_0000_0000_0000
c. -13.375
1100_0001_0101_0110_0000_0000_0000_0000
d. 13.625
0100_0001_0101_1010_0000_0000_0000_0000
6. Convert the following floating point binary numbers to decimal
sign (1) exponent (8) mantissa (23)
a. 1011_1101_0000_0000_0000_0000_0000_0000
-0.03125
a. 1100_0000_0010_0011_0011_0011_0011_0011
-2.5499999523162841796875
b. 0100_0011_0000_1111_0000_0000_0000_0000
143
c. 1100_0001_1000_1110_0000_0000_0000_0000
-17.75
C Pointers
1. What are the values in arr after the following code executes?:
int val = 120;
int * ptr = &val;
int a = 12;
int ** pptr = &ptr;
val = a;
int arr[] = { 11, 2, 35, 469 };
*(arr + 2) = **pptr;
Solution: arr = {11, 2, 12, 469 }
2. What is the value of c after the following code executes?
char * str = “cse30fa19”;
char ** pptr = &str;
char c = *((*pptr) + 6);
Solution: c = ‘a’
3. What are the values of x, y, and z after the following code executes?
int arr[] = { 7, -11, 30, 104 };
int * p = arr;
int x = *p++;
int y = *(p++);
int z = *p - 3;
Solution: x=7 y=-11 z=27
4. What is the value of x after the following code executes?
int a[] = { 1, 0, 10 };
int b[] = { 2, 3, 6, 7 };
int * one = a;
int * two = b;
int ** three = &one;
int ** four = &two;
one = two;
int x = *(*three + 2);
Solution: x=6
5. Which char does a point do by the end of this code?
char * a = “kitten”;
char * b = a;
char ** c = &b;
*c = a + 2;
Solution: a points to ‘k’ (stores the address of the ‘k’)
6.
a. What will the following code print?
void swap( int a, int b){
a = a ^ b;
b = a ^ b;
a = a ^ b;
}
int x = 5;
int y = 100;
printf(“before swap x = %d y = %d\n”, x, y);
swap(x, y);
printf(“after swap x = %d y = %d\n”, x, y);
before swap x = 5 y = 100
after swap x = 5 y = 100
b. If this code needs to be fixed, modify it so that it performs the intended task.
We need to pass pointers to use pointers to allow the values of x and y to be
modified.
void swap( int *a, int *b){
*a = *a ^ *b;
*b = *a ^ *b;
*a = *a ^ *b;
}
int x = 5;
int y = 100;
printf(“before swap x = %d y = %d\n”, x, y);
swap(&x, &y);
printf(“after swap x = %d y = %d\n”, x, y);
7. Given the following arguments, what is printed when the following code executes?
(Answer A-E, where each code segmented is inserted into the main method shown
below.)