230 Midterm #2
Predict the output of the below program. int main() { char arr[] = {1, 2, 3}; char *p = arr; if(&p == &arr) printf("Same"); else printf("Not same"); getchar(); }
"Not Same"
1 int main() { 2 char a[] = "hello"; 3 int *int_ptr = 0; 4 int_ptr = a[1]; 5 printf("%d\n", int_ptr); 6} (a) What two warnings will occur during compilation? State where and why. (b) What value does line 5 print? Hint: think about the ASCII table.
(a) Line 4 assigns a char to an *int (incompatible conversion). Line 5 uses an int format specifier, then passes *int as the actual argument. (b): 101
Which of the following is NOT a caller-save register? (a) %eax, (b) %ebx, (c) %ecx, (d) %edx
(b) %ebx
If a process contains if(!fork()) execve(...), what aspects of virtual memory do the child and parent share after execve()? (a) stack space (b) heap space (c) read only space (d) nothing
(d) nothing
Enter the number of registers on a IA-32 bit system ____ x 64 bit registers _____x 32 bit registers _____ 16 bit registers _____ 8 bit registers _____ 1 bit registers
0 8 8 0 8
Which case may create a zombie process? A. Child process is terminated before parent process B. Child process is terminated after parent process C. Parent process is terminated before child process D. Parent process is terminated after child process
A
Assume that the size of an integer is 4 bytes. Predict the output? #include <stdio.h> int fun() { puts(" Hello "); return 10; } int main() { printf("%d", sizeof(fun())); return 0; } A 4 B Hello 4 C 4 Hello D Compiler Error
A 4
What does a shell program do?
A shell program runs the other programs
which of the following assembly code represents frame pointer? A. %ebp B. %esp C. %efp D. %edp
A. %ebp
Memory components such as registers and caches are ______ than other memory components, while for example main memory (DRAM) and local disks tend to be _______.
A. smaller faster and costlier, larger slower and cheaper
What is the term for the ability of a processor to guess whether or not a jump instruction will be followed? a. "branch prediction logic" b. "temporal locality" c. "spatial locality" d. "conditional move" e. "none of these"
a. "branch prediction logic"
Which would you use to get the process id? a. getpid b. getppid c. getidp d. getprocessid
a. getpid
Which part of the Control Unit of the von Neumann architecture "stores the current instruction"? a. instruction register b. instruction counter c. status register d. decoder e. signal generator
a. instruction register
The pipe system call will open two "files": pipefd[0] for [Blank a.] pipefd[1] for [Black b.]
a. reading b. writing
Which part of the Control Unit of the von Neumann architecture " interprets the instruction and figures out what signals to generate" ? a. instruction register b. instruction counter c. status register d. decoder e. signal generator
b. decoder
How does the machine execute a program ? (What cycle?) a. fetch, store , execute b. fetch, decode, execute c. run, store, execute d. execute, store, decode e. none of the above
b. fetch,decode, execute
Which part of the Control Unit of the von Neumann architecture "stores the address of the next instruction" ? a. instruction register b. instruction counter c. status register d. decoder e. signal generator
b. instruction counter
The ebp register contains the address of the [blank] element of the current stack frame. The esp register contains the address of the [blank] element of the current stack frame.
bottom, top
In a pipeline execution using branch prediction, what happens to the performance of the program if the prediction is incorrect? a. stays the same b. massive speedup c. big performance difference (slow down) d. none of the above
c. big performance difference (slow down)
Which of the following commands the processor to move 4 bytes of data? a. movb b. movw c. movel d. moves e. none of these
c. movel
Which part of the Control Unit of the von Neumann architecture "stores information about the result of the last operation" ? a. instruction register b. instruction counter c. status register d. decoder e. signal generator
c. status register
Imagine a struct "Node" with 2 members, 1 pointer to another Node called ptr, which is the first member, and an integer value. If you were to construct an array of length 2 which has a Node head, which points to a Node tail; and the Node tail which, in fact, points to the head Node. What would the line of code: printf("%d", *(tail + sizeof(Node *))) print out? a. The value of Node Tail b. The address of head c. The address of tail->ptr d. The value of Node head
d
What can you do with stack frame storage? a. "Pass procedural arguments" b. "save registers for later restoration" c. "local storage", d. "all of these" e. "none of these"
d. "all of these"
Which is NOT a valid movl operand combination? a. $0x8, $edx b. $eax, $edx c. $(eax), %edx d. $(eax), %(edx)
d. $(eax), %(edx)
Which is NOT a state that a process can be in? a. Terminated b. Running c. Stopped d. Crawling
d. Crawling
Which of the following is a type of processor operands? a. Immediate b. register c. memory d. all of these e. none of these
d. all of these
Which part of the Control Unit of the von Neumann architecture "communicates with the rest of the processor" ? a. instruction register b. instruction counter c. status register d. decoder e. signal generator
e. signal generator
Which of the following registers are managed by the calling function? eax, ecx, edx, ebx, esi, edi, esp, ebp
eax, edx, ecx
Which of the following registers is responsible for keeping track of beginning of the current frame? eax, ecx, edx, ebx, esi, edi, esp, ebp
ebp
Which of the following registers are managed by the called function? eax, ecx, edx, ebx, esi, edi, esp, ebp
ebx, esi, edi
Which of the following registers is responsible for keeping track of the top of the stack? eax, ecx, edx, ebx, esi, edi, esp, ebp
esp
In the expression ++*p, the precedence of prefix ++ is [ ] *, so you need first operate [ ], second operate [ ].
same, * and ++
Consider the following IA32 assembly code for the main function: 1 pushl %ebp 2 movl %esp, %ebp 3 subl $16, %esp 4 movl $2, -4(%ebp) 5 movl $3, -8(%ebp) 6 movl -4(%ebp), %edx 7 movl -8(%ebp), %eax 8 addl %edx, %eax 9 movl %eax, -12(%ebp) 10 movl $0, %eax 11 leave 12 ret which line is moving value 3 into a register?
line 7
The ___ function in C is used to allocate memory on the _____.
malloc, heap
A C [blank] translates C programs into instructions that are understood by the machine
Compiler
Predict the output of below programs: #include‹stdio.h› int main() { struct book { char title[] = "Computer Systems: A Programmer's Perspective"; int number_of_pages = 200; }; struct book *ptr; printf("%d",ptr->number_of_pages); printf("%s",ptr->title); getchar(); return 0; }
Compiler Error
A process is in one of the three states: a)Running b)Stopped c)Terminated d)All of the Above e)None of the Above
D
Predict the output of the below program #define square(x) x*x int main() { int x; x = 36/square(6); printf("%d",x); getchar(); return 0; } A. 6 B. 12 C. 24 D. 36 E. cannot compile
D
What does line 3 represent in assembly? 1 void foo() { 2 char bar[16]; 3 bar[9] = 'm'; 4 } In assembly, the code represents: pushl %ebp // Setting up stack frame movl %esp %ebp subl $32, %ebp // Allocating space on stack for array A) movb $109, 9(%ebp) B) movb $77, -7(%ebp) C) movb, -9(%ebp), %esp D) movb $109, -7(%ebp) E) None of the above
D
Where are register files located on a PC? A. Graphics card B. Main Memory C. Hard Disk D. CPU"
D. CPU
"Consider the following c program: void swap(char ** a, char**b) { char ** temp = a; a = b; b = a; } int main() { char * s1 = ""grim""; char* s2 = ""reaper""; swap(&s1, &s2); printf(""%c %c"", s1, s2); return 0; } What does the program print? A. grim reaper B. reaper grim C. reaper reaper D. g r"
D. g r"
Variables that are local to a function are allocated in a corresponding frame. For the IA32 32-bit Linux environment, which of the following registers is used for allocating local variables in such a stack frame? A. %ebx B. %ebp C. %eip D. %edx E. %esp
E
Which registers are reserved
EIP, ESP, EBP
The Arithmetic Logic Unit (ALU) is part of which component of the von Neumann architecture.
Execution unit
True or False: Processes always print things in the order that they appear in code (or in the order that they are created).
FALSE
In assembly, memory-memory transfer can be performed in a single instruction. True or false?
False
Killing a parent process will also kill all its child process
False
The shell catches the signal from Ctrl-C and then sends a SIGINT to the process in the [Blank]process group.
Foreground
CPU supports a number of different registers. The %eax register is one of these registers, which of the following categories does this register belong to?
General purpose registers
When a process is forked, it gets a copy of the parent's virtual address space, with
Heap and stack
The GCC compiler translates your C programs into "human readable format" known as
Assembly
For the IA32 32-bit Linux environment, which of the following registers points to the start of the frame for the currently executing function? A. %ebx B. %ebp C. %eip D. %edx E. %esp
B
How does the stack grow? A. Downwards, with %esp pointing to the highest address in the stack B. Downwards, with %esp pointing to the lowest address in the stack C. Upwards, with %esp pointing to the highest address in the stack D. Upwards, with %esp pointing to the lowest address in the stack
B
Which is not a state of a process? A. Terminated B. Waiting C. Stopped D. Running
B
Which of the following are at the top of the memory hierarchy? A. memory B. registers C. Cache D. disk E. The network
B
Where on the stack that callee frame used to save caller's old %ebp value? A. The heap B. At a negative offset from the %ebp register C. In the %edx register D. At a negative offset from the %esp register
B. At a negative offset from the %ebp register
In what phase in the compilation system does the OS merge C library functions defined by the "#include" deceleration in the C source code? A. Preprocessing phase B. Linking Phase C. Assembly Phase D. Compilation Phase"
B. Linking Phase
Which of the following statements about process is false? A. The environment for a process is stored on the stack. B. The operating system kernel runs as its own separate process. C. Each process shares the CPU with other processes. D. Each process has its own private address space.
B. The kernel itself is not a process, it executes handler code on behalf of processes running on top of it.
how can you print a string? char str[] = "abc"; A. printf("%c\n", str); B. printf("%s\n", str); C. printf("%c\n", *str); D. printf("%d\n", str);
B. printf("%s\n", str);
#include <stdio.h> int main() { char *c = "Testing "; printf("Guess what the answer is: %c\n", *&*(c+6)); // The answer is g printf("Guess what the answer is: %c\n", *&*(c+7)); // Look carefully return 0; } A: Testing B: Blank C: g D: I got this idea from GeeksforGeeks here is the link https://www.geeksforgeeks.org/c-language-2-gq/pointers-gq/ Look at question 8
B: Blank
Electrical conduits running throughout the system called _____ carry bytes of information back and forth between components.
Buses
For the IA32 32-bit Linux environment Which of the following registers is used by the compiler to return a value from a function? A. %ebx B. %ebp C. %eip D. %edx E. %esp
C
Consider this fragment of C code: 1 t main() { 2 if (fork() || fork()) fork(); 3 printf("hello\n"); 4 exit(0); 5 return 0;} How many "hello"s will be printed? A. 8 B. 3 C. 5 D. 6 E. 7
C. 5
In binary how do we get the two's complement of a number? "A. set the sign bit to 1 and leave all the other bits unchanged B. complement all the bits C. complement all the bits and add 1 D. set all the unsigned bits to 1 and add 2"
C. complement all the bits and add 1
In what form does the life of a C program begin? A. assembly code file B. executable object file C. source program D. relocatable object file"
C. source program
How do we communicate to processes?
Signal and pipe