CSE 30 Final Exam Summer 2018
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
CSE 30
Final Exam
Summer 2018
Problem 1 (9 pts): Number Systems a) (3 pts). Convert 0xFFCE (2’s complement format, 16-bit word) to the following. binary_____________________________________ (straight base conversion to binary) octal_______________________________________ (straight base conversion) decimal____________________________________ (convert to signed decimal) b) (3 pts). Convert 152 to the following (assume 16-bit word). Express answers in hexadecimal. sign-magnitude_______________________________________________ 1’s complement_______________________________________________ 2’s complement_______________________________________________ c) (3 pts). Convert -633 to the following (assume 16-bit word). Express answers in hexadecimal. sign-magnitude_______________________________________________ 1’s complement_______________________________________________ 2’s complement_______________________________________________
Problem 2 (4 pts): Rt-Lt Rule a) (2 pts). Using the C Rt-Lt Rule, define a variable named foo that is a pointer to a function which has a single parameter as a pointer to a struct fubar and returns a pointer to an array of 20 elements where each element is of type int pointer.
b) (2 pts). Using the Rt-Lt Rule, write the C variable definition for the variable named foo that is a pointer to a 2D array with 10 rows and 20 columns where each element of the array is a pointer to a function that has no parameter and returns an int.
Problem 3 (9 pts): Binary Addition/Condition Code Bits/Overflow Detection
Indicate what the condition code bits are when adding the following 8-bit 2’s complement numbers. Also provide the sum for each problem.
11010101
10001111
------------
N |
Z |
V |
C |
|
|
|
|
11111111
+ 01111111
------------
N |
Z |
V |
C |
|
|
|
|
11110000
+ 00001111
------------
N |
Z |
V |
C |
|
|
|
|
Problem 4 (6 pts): Bitwise Operations
What is the value (in hex) of r1 after each set of instructions. Assume that r0 and r1 start with the value in the comment section. Make sure you write your answer as 32 bit words.
a). @ r0 = 0xDEADFACE
and r1, r0, #0xBABEFACE
Value in r1 at this point is 0x______________________________________________
b). @ r0 = 0XBEEFFACE
@ r1 = 0xDEEDBABE
eor r1, r0, r1
Value in r1 at this point is 0x______________________________________________
c). @r0 = 0x02468ACE
@r1 = 0x13579BDF
orr r1, r0, r1
Value in r1 at this point is 0x______________________________________________
d). @ r0 = 0xBAD5BABE
lsl r1, r0, #12
Value in r1 at this point is 0x______________________________________________
e). @ r0 = 0x87654321
asr r1, r0, #9
Value in r1 at this point is 0x______________________________________________
f). @ r0 = 0xBEEFBABE
lsr r1, r0, #4
Value in r1 at this point is 0x______________________________________________
Problem 5 (27 pts): if statements with short-circuiting
Write the correct instructions to form the correct
sequence to translate the C code below into the
equivalent ARM assembly code. You should use the
approach we covered in lectures to translate. You
should assume that all local variables are mapped to
the stack. There are exactly the same number of lines
you should use. You should always assume the
independence of statements. For example, if a
variable needs to be modified, you should always
load from the memory no matter what you have
stored in your registers in previous statements.
// C code /* Assume variables a and b have been properly declared as ints. A is the first declared local variable, and b is the second declared local variable.*/ if (a + b > 5 || b - 1 == 10){ b = a++ + 10; } else{ b = ++a + 5; } a++; |
|
@ARM Assembly @use r0 to manipulate a @use r1 to manipulate b @use r2 as temporary storage @one instruction is given
ldr ____________________ ldr ____________________ add ____________________
____________________
____________________ ldr ____________________
____________________
____________________
____________________ @continue on the right |
|
Problem 6 (20 pts): C runtime environment
Given the following program, reorder the output so that the address values that are printed are sorted from smallest to largest if compiled and run on our pi-cluster. These lines print out the hex address of the different parts of the program (not the values assigned) with the printf() format specifier %p (pointer). Basically, where do the different parts of a C program live in the run time environment? Write the correct letters in the answer area.
#include <stdio.h> int y; int foo (int a, char b, short c) { int d; printf("&a = %p\n", &a); //A printf("&b = %p\n", &b); //B printf("&c = %p\n", &c); //C printf("&d = %p\n", &d); //D } int fubar (int x1, int x2, int x3, int x4, int x5, int x6, int x7) { int tmp; double r; printf("&x1 = %p\n", &x1); printf("&x2 = %p\n", &x2); printf("&x3 = %p\n", &x3); printf("&x4 = %p\n", &x4); printf("&x5 = %p\n", &x5); printf("&x6 = %p\n", &x6); printf("&x7 = %p\n", &x7); printf("&tmp = %p\n", &tmp); printf("&r = %p\n", &r); } int main(int argc, char* argv[]) { int m; char n; static short x = 10; printf("main = %p\n", main); printf("&x = %p\n", &x); printf("&y = %p\n", &y); printf("&argc = %p\n", &argc); printf("&argv = %p\n", &argv); printf("&m = %p\n", &m); printf("&n = %p\n", &n); foo(1,2,3); fubar(x, y, 3, 4, 5, 6, 7); } |
Problem 7 (29 pts). Stack Frame
Given the C code below, first complete the memory stack. Clearly mark the location of fp and sp in the stack frame by writing sp and fp on the left side of the memory location it points to. Then fill in the blanks to complete the translation from C to ARM assembly. Part B is on the next page.
2022-09-04