CPSC 213, Winter 2016, Term 2 Final Exam Date: April 19, 2017; Instructor: Mike Feeley and Alan Wagner
|
|
- Cori Eaton
- 5 years ago
- Views:
Transcription
1 CPSC 213, Winter 2016, Term 2 Final Exam Date: April 19, 2017; Instructor: Mike Feeley and Alan Wagner This is a closed book exam. No notes or electronic calculators are permitted. You may remove the last page. Answer in the space provided. Show your work; use the backs of pages if needed. There are 15 questions on 16 pages, totaling 103 marks. You have 3 hours to complete the exam. STUDENT NUMBER: NAME: SIGNATURE: Q1 / 4 Q2 / 6 Q3 / 6 Q4 / 8 Q5 / 4 Q6 / 9 Q7 / 10 Q8 / 9 Q9 / 6 Q10 / 6 Q11 / 6 Q12 / 8 Q13 / 9 Q14 / 6 Q15 / 6 1 (4 marks) Variables and Memory. Consider the following code running on 32-bit, big-endian architecture. struct S { char a[4]; ; int i; struct S* s; char foo() { i = 0x ; s = (struct S*) &i; return s->a[1]; Does the procedure foo() compile and execute without error? If not, what is the error? If so, can you determine what value it returns? If so, what is that value?
2 2 (6 marks) Global Variables. Consider the following C declaration of global variables. Give the SM213 assembly code for each of the following C statements. Use labels such as a, b etc. for statically know values. Comments are not required. You can treat your answers as a sequence and thus use register values loaded in one subquestion in subsequent ones to avoid duplication. int a; int* b; int* c[10]; 2a b = &a; 2b a = b[a]; 2c a = *c[a]; 2
3 3 (6 marks) Instance and Local Variables. Give the SM213 assembly code for the following statements that access elements of global and local structs. Consider each statement as if it were the last line of foo() at the location indicated by the comment. Use labels such as a, b etc. for statically known values. Assume that r5 stores the value of the stack pointer. Comments are not required. You can treat your answers as a sequence and thus use register values loaded in one subquestion in subsequent ones to avoid duplication. struct S { int w; int x; struct S* y; struct T z; ; struct T { int w; int x; ; int i; struct S* a; void foo() { struct S* b; // QUESTION CODE IS HERE 3a i = a->y->x; 3b i = a->z.x; 3c i = b->x; 3
4 4 (8 marks) Reading Assembly Code. Consider the following SM213 assembly procedure defined as int foo(int n). The procedure used the call/return conventions described in class where register r5 is the stack pointer. Register r0 is used to store the return value of the function. foo: deca r5 # deca r5 # st r6, 4(r5) # ld 8(r5), r1 # bgt r1, L1 # ld $0, r2 # br L3 # L1: dec r1 # bgt r1, L2 # ld $1, r2 # br L3 # L2: ld 8(r5), r1 # dec r1 # deca r5 # st r1, 0(r5) # gpc $0x6, r6 # j foo # inca r5 # st r0, 0(r5) # ld 8(r5), r1 # dec r1 # dec r1 # deca r5 # st r1, 0(r5) # gpc $0x6, r6 # j foo # inca r5 # ld (r5), r2 # add r0, r2 # L3: mov r2,r0 # ld 4(r5), r6 # inca r5 # inca r5 # j (r6) # 4a Carefully comment every line of code above. 4
5 4b Convert the assembly into C. 4c The code implements a simple function. What is it? Give the simplest, plain English description you can. 5 (4 marks) Procedure Calls. Given these global declarations int x; int (*proc) (int); Give the SM213 assembly for the code below (just for this single statement, not for the procedure itself). Assume that the return value is in r0. Comments are not required. x = proc (1); 5
6 6 (9 marks) C Pointers and Functions Consider the following C code. void foo(int x, int *p) { A. printf("x = %d, *p = %d", x, *p); *p = x + 12; --x; p = 0; int main (void) { int a = 1; int b = 2; int *p = &a; int **q = &p; B. printf("**q = %d", **q); foo(*p, *q); C. printf("a = %d", a); if (!p) D. printf("p is 0"); else E. printf("*p is %d", *p); *q = &b; F. printf("*p = %d", *p); return 0; In the above code, what if anything is printed by the printf instruction at locations A to F when the program is executed? 6a A 6b B 6c C 6d D 6e E 6f F 6
7 7 (10 marks) Allocation in C. You are giving expert advice to a development team about what type of variable allocation strategy is ideal for various aspects of their system. Indicate which of the following five strategies best suits each of the scenarios listed below (a strategy can apply to more than one scenario and some strategies may not be best for any of them). Name the strategy using its letter (i.e., A-E) and justify your answer briefly. Strategies Scenarios A. Global variable storing the entire object in question. B. Local variable storing the entire object in question. C. Calling malloc and free in the same procedure. D. Calling malloc and free in different procedures. E. Calling malloc and using reference counting instead of calling free. 7a An object that is allocated when a procedure is called and deallocated when it returns, where the primary concern is to prevent memory leaks and to simplify the code for allocation and deallocation. 7b An object that is allocated when a procedure is called and deallocated when it returns, where the primary concern is to prevent stack-smash, buffer-overflow attacks. 7c A dynamically-allocated object whose lifetime can only be determined by understanding the implementation of multiple procedures in different modules of the program. 7d An object whose size is independent of program inputs and that exists for the entire execution of the program, where the primary concern is to minimize runtime costs (i.e., CPU time) for allocating and accessing the object. 7e An object whose size depends on program inputs and that exists for the entire execution of the program, where the primary concern is to efficiently handle a very wide range of input values. 7
8 8 (9 marks) C Memory Errors. There are four memory related errors in the program below. For each error, give the line number on which the error occurred, the type of error, and indicate how to fix it. 1 struct my_struct { 2 int nnums; 3 int *nums; 4 ; typedef struct my_struct *my_struct_t; 5 void foo(my_struct_t ptr) { 6 int i; 7 for (i = 0; i <= ptr->nnums; i++) { 8 printf("%d", ptr->nums[i]); 9 10 free(ptr); int main(void) 13 { 14 my_struct_t s = malloc(sizeof(s)); 15 s->nnums = 5; 16 s->nums = malloc(5 * sizeof(*s->nums)); 17 for (int i = 0; i < s->nnums; i++) { 18 s->nums[i] = i + 4; foo(s); 21 free(s); 22 return 0; 23 8a Error 1: line: type: fix: 8b Error 2: line: type: fix: 8
9 8c Error 3: line: type: fix: 8d Error 4: line: type: fix: 9 (6 marks) Reference Counting. The following code has a memory leak bug. Add calls to inc(o) and dec(o) to increment and decrement the reference count of object o and make any other small changes necessary so that the program is free of memory leaks and dangling pointers. Assume that rc_malloc calls malloc and initializes the object s reference count to zero. void foo (int i) { int* ip = rc_malloc (sizeof (int)); int c = 0; int* v[2]; *ip = i; bar (ip); void bar (int* ap) { if (v[c] == NULL *ap < *v[c]) { zot (*ip); v[c] = ap; c = (c + 1) % 2; void zot (int a) { if (v[c]!= NULL && a < *v[c]) *v[c] = a; c = (c + 1) % 2; 9
10 10 (6 marks) Using Function Pointers. Write a C procedure named apply that returns either the minimum or maximum value of a list of non-negative integers, as determined by one of its parameters, a function pointer. If the list is empty it should return -1. Assume the existence of procedures named min(a,b) and max(a,b) that compare two integers and returns the min or max integer. No other procedures are allowed and apply is not permitted to use an if statement. For example, the following statement should compute the maximum value in list a of length n. int m = apply (max, a, n); Write the procedure apply(): 11 (6 marks) IO Devices. For each of the following, (a) explain what it is and (b) state whether the CPU or IO controller determines when it occurs (i.e., initiates it). 11a Programmed IO (PIO): 11b DMA: 11c Interrupts: 10
11 12 (8 marks) Threads and Scheduling. Answer the following questions about threads. 12a Explain briefly (without giving any code) how threads can be used to simplify code that performs asynchronous operations such as communicating with an IO controller. 12b Explain briefly the difference between uthread_yield and uthread_block. 12c Is it possible for a thread to unblock itself? Explain your answer. 12d Consider a system in which there is at least one thread on the ready queue when a thread unblocks. What happens to the unblocked thread? Explain. 11
12 13 (9 marks) Synchronization Consider the following C code that uses mutexes and condition variables. The code is considered to be is correct if both procedures complete successfully when they are called from concurrent threads (i.e., one thread calls procx and the other calls procy). Indicate whether or not the code is correct. If it is correct, describe why. If it is not correct, carefully describe the problem; you must be specific. All variations share the following declarations. Note that initialization code is omitted for brevity; you should assume that all variables were initialized correctly. int flag = 0; uthread_mutex mx; uthread_cond condx, condy; 13a void procx() { for (int i=0; i<100; i++) { uthread_cond_signal (condx); uthread_cond_wait (condy); void procy() { for (int i=0; i<100; i++) { uthread_cond_signal (condy); uthread_cond_wait (condx); Is this code correct? Justify your answer. 13b void procx() { uthread_mutex_lock (mx); for (int i=0; i<100; i++) { uthread_cond_signal (condx); uthread_cond_wait (condy); uthread_mutex_unlock (mx); void procy() { uthread_mutex_lock (mx); for (int i=0; i<100; i++) { uthread_cond_signal (condy); uthread_cond_wait (condx); uthread_mutex_unlock (mx); Is this code correct? Justify your answer. 12
13 13c void procx() { uthread_mutex_lock (mx); for (int i=0; i<100; i++) { uthread_cond_signal (condx); if (i!=0 flag==0) { flag = 1; uthread_cond_wait (condy); uthread_mutex_unlock (mx); void procy() { uthread_mutex_lock (mx); for (int i=0; i<100; i++) { uthread_cond_signal (condy); if (i!=0 flag==0) { flag = 1; uthread_cond_wait (condx); uthread_mutex_unlock (mx); Is this code correct? Justify your answer. 13
14 14 (6 marks) Semaphores. Add semaphores to the code shown below to guarantee that the program always prints do...re...me. Add code in the blank areas, if necessary. You can only use the uthread_sem_t API: uthread_sem_create(int), uthread_sem_wait(uthread_sem_t), and uthread_sem_signal(uthread_sem_t). #include <stdio.h> void* doe(void* p) { printf("do..."); return 0; void* re(void* p) { printf("re..."); return 0; void* me(void* p) { printf("me"); return 0; int main (int argc, char** argv) { uthread_t at,bt,ct; uthread_init(3); at = uthread_create (doe,null); bt = uthread_create (re,null); ct = uthread_create (me,null); uthread_join(at,0); uthread_join(bt,0); uthread_join(ct,0); 14
15 15 (6 marks) Deadlock. Consider these three procedures that are allowed to run concurrently in different threads. void one() { uthread_mutex_lock (a); uthread_mutex_lock (b);... uthread_mutex_unlock (b); uthread_mutex_unlock (a); void two() { uthread_mutex_lock (b); uthread_mutex_lock (c);... uthread_mutex_unlock (c); uthread_mutex_unlock (b); void three() { uthread_mutex_lock (c); uthread_mutex_lock (a);... uthread_mutex_unlock (a); uthread_mutex_unlock (c); Can this program deadlock? Explain briefly. 15
16 These two tables describe the SM213 ISA. The first gives a template for instruction machine and assembly language and describes instruction semantics. It uses s and d to refer to source and destination register numbers and p and i to refer to compressed-offset and index values. Each character of the machine template corresponds to a 4-bit, hexit. Offsets in assembly use o while machine code stores this as p such that o is either 2 or 4 times p as indicated in the semantics column. The second table gives an example of each instruction. With the exception of pc-relative branches and shift, all immediate values stored in instructions are unsigned. Operation Machine Language Semantics / RTL Assembly load immediate 0d-- vvvvvvvv r[d] v ld $v,rd load base+offset 1psd r[d] m[(o = p 4) + r[s]] ld o(rs),rd load indexed 2sid r[d] m[r[s] + r[i] 4] ld (rs,ri,4),rd store base+offset 3spd m[(o = p 4) + r[d]] r[s] st rs,o(rd) store indexed 4sdi m[r[d] + r[i] 4] r[s] st rs,(rd,ri,4) halt F000 (stop execution) halt nop FF00 (do nothing) nop rr move 60sd r[d] r[s] mov rs, rd add 61sd r[d] r[d] + r[s] add rs, rd and 62sd r[d] r[d] & r[s] and rs, rd inc 63-d r[d] r[d] + 1 inc rd inc addr 64-d r[d] r[d] + 4 inca rd dec 65-d r[d] r[d] 1 dec rd dec addr 66-d r[d] r[d] 4 deca rd not 67-d r[d] r[d] not rd shift 7dss r[d] r[d] << s shl $s, rd (if s is negative) shr $-s, rd branch 8-pp pc (a = pc + p 2) br a branch if equal 9rpp if r[r] == 0 : pc (a = pc + p 2) beq rr, a branch if greater Arpp if r[r] > 0 : pc (a = pc + p 2) bgt rr, a jump B--- aaaaaaaa pc a j a get program counter 6Fpd r[d] pc + (o = 2 p) gpc $o, rd jump indirect Cdpp pc r[d] + (o = 2 p) j o(rd) jump double ind, b+off Ddpp pc m[(o = 4 p) + r[d]] j *o(rd) jump double ind, index Edi- pc m[4 r[i] + r[d]] j *(rd,ri,4) Operation Machine Language Example Assembly Language Example load immediate ld $0x1000,r1 load base+offset 1123 ld 4(r2),r3 load indexed 2123 ld (r1,r2,4),r3 store base+offset 3123 st r1,8(r3) store indexed 4123 st r1,(r2,r3,4) halt f000 halt nop ff00 nop rr move 6012 mov r1, r2 add 6112 add r1, r2 and 6212 and r1, r2 inc 6301 inc r1 inc addr 6401 inca r1 dec 6501 dec r1 dec addr 6601 deca r1 not 6701 not r1 shift 7102 shl $2, r1 71fe shr $2, r1 branch 1000: 8003 br 0x1008 branch if equal 1000: 9103 beq r1, 0x1008 branch if greater 1000: a103 bgt r1, 0x1008 jump b j 0x1000 get program counter 6f31 gpc $6, r1 jump indirect c104 j 8(r1) jump double ind, b+off d102 j *8(r1) jump double ind, index e120 j *(r1,r2,4) 16
CPSC 213, Winter 2016, Term 2 Final Exam Solution Date: April 19, 2017; Instructor: Mike Feeley and Alan Wagner
CPSC 213, Winter 2016, Term 2 Final Exam Solution Date: April 19, 2017; Instructor: Mike Feeley and Alan Wagner 1 (4 marks) Variables and Memory. Consider the following code running on 32-bit, big-endian
More informationCPSC 213, Winter 2013, Term 2 Final Exam Date: April 14, 2014; Instructor: Mike Feeley
CPSC 213, Winter 2013, Term 2 Final Exam Date: April 14, 2014; Instructor: Mike Feeley This is a closed book exam. No notes or electronic calculators are permitted. Answer in the space provided. Show your
More informationCPSC 213, Summer 2017, Term 2 Midterm Exam Date: July 27, 2017; Instructor: Anthony Estey
CPSC 213, Summer 2017, Term 2 Midterm Exam Date: July 27, 2017; Instructor: Anthony Estey 1. This is a closed book exam. No notes. No electronic calculators. 2. Answer in the space provided. Show your
More informationCPSC 213, Winter 2009, Term 2 Midterm Exam Date: March 12, 2010; Instructor: Mike Feeley
CPSC 213, Winter 2009, Term 2 Midterm Exam Date: March 12, 2010; Instructor: Mike Feeley This is a closed book exam. No notes. Electronic calculators are permitted. Answer in the space provided. Show your
More informationCPSC 213. Introduction to Computer Systems. Static Scalars and Arrays. Unit 1b
CPSC 213 Introduction to Computer Systems Unit 1b Static Scalars and Arrays 1 Reading for Next 3 Lectures Companion 2.4.1-2.4.3 Textbook Array Allocation and Access 3.8 2 The Big Picture Build machine
More informationCPSC 213. Introduction to Computer Systems. Scalars and Arrays. Unit 1b
CPSC 213 Introduction to Computer Systems Unit 1b Scalars and Arrays 1 Reading Companion 2.2.3, 2.3, 2.4.1-2.4.3, 2.6 Textbook Array Allocation and Access 1ed: 3.8 2ed: 3.8 2 Design Plan 3 Examine Java
More informationCPSC213/2014W1 Midterm EXTRA Practice
CPSC213/2014W1 Midterm EXTRA Practice DEC/HEX/BIN NUMERACY 1. Convert into decimal: 1a. 0x33 1b. 0x57 1c. 0xaf 1d. 0x7a 1e. 0x1234 1f. 0x69bd 1g. 0x1a64 1h. 0xdead 2. Convert into hex numbers of the specified
More informationCPSC 213. Introduction to Computer Systems. Instance Variables and Dynamic Allocation. Unit 1c
CPSC 213 Introduction to Computer Systems Unit 1c Instance Variables and Dynamic Allocation 1 Reading For Next 3 Lectures Companion 2.4.4-2.4.5 Textbook Structures, Dynamic Memory Allocation, Understanding
More informationCPSC 213. Introduction to Computer Systems. Winter Session 2017, Term 2. Unit 1c Jan 24, 26, 29, 31, and Feb 2
CPSC 213 Introduction to Computer Systems Winter Session 2017, Term 2 Unit 1c Jan 24, 26, 29, 31, and Feb 2 Instance Variables and Dynamic Allocation Overview Reading Companion: Reference 2.4.4-5 Textbook:
More informationReading. Companion. Text. - yup, 3.10 again - mainly "Function pointers" box. 1ed: 3.6.6, in Java. static methods are class methods
Reading Companion CPSC 213 Introduction to Computer Systems 2.7.4, 2.7.7-2.7.8 Text Switch Statements, Understanding Pointers 2ed: 3.6.7, 3.10 - yup, 3.10 again - mainly "Function pointers" box 1ed: 3.6.6,
More informationCPSC 213, Summer 2017, Term 2 Midterm Exam Solution Date: July 27, 2017; Instructor: Anthony Estey
CPSC 213, Summer 2017, Term 2 Midterm Exam Solution Date: July 27, 2017; Instructor: Anthony Estey 1 (10 marks) Memory and Numbers. Consider the following C code containing global variables a, b, c, and
More informationCPSC 213. Introduction to Computer Systems. Dynamic Control Flow. Unit 1f Feb 28, Mar 2, 5, 7 and 9. Winter Session 2017, Term 2
CPSC 213 Introduction to Computer Systems Winter Session 2017, Term 2 Unit 1f Feb 28, Mar 2, 5, 7 and 9 Dynamic Control Flow Overview Reading Companion: 2.7.4, 2.7.7-2.7.8 Reference Text: 3.6.7, 3.10 Learning
More informationCPSC 213. Introduction to Computer Systems. Static Control Flow. Unit 1d
CPSC 213 Introduction to Computer Systems Unit 1d Static Control Flow 1 Reading Companion 2.7.1-2.7.3, 2.7.5-2.7.6 Textbook 3.6.1-3.6.5 2 Control Flow The flow of control is the sequence of instruction
More informationCPSC 213. Introduction to Computer Systems. Procedures and the Stack. Unit 1e Feb 11, 13, 15, and 25. Winter Session 2018, Term 2
CPSC 213 Introduction to Computer Systems Winter Session 2018, Term 2 Unit 1e Feb 11, 13, 15, and 25 Procedures and the Stack Overview Reading Companion: 2.8 Textbook: 3.7, 3.12 Learning Goals explain
More informationCPSC 213. Introduction to Computer Systems. Reading. Control Flow. Loops (S5-loop) Static Control Flow. Unit 1d. Companion.
Reading Companion CPSC 213 2.7.1-2.7.3, 2.7.5-2.7.6 Textbook 3.6.1-3.6.5 Introduction to Computer Systems Unit 1d Static Control Flow Control Flow 1 Loops (S5-loop) 2 The flow of control is the sequence
More informationCPSC 213. Introduction to Computer Systems. Readings for Next 2 Lectures. Loops (S5-loop) Control Flow. Static Control Flow. Unit 1d.
Readings for Next 2 Lectures Textbook CPSC 213 Condition Codes - Loops 3.6.1-3.6.5 Introduction to Computer Systems Unit 1d Static Control Flow Control Flow 1 Loops (S5-loop) 2 The flow of control is the
More informationCPSC 213. Introduction to Computer Systems. Static Control Flow. Unit 1d
CPSC 213 Introduction to Computer Systems Unit 1d Static Control Flow 1 Reading Companion 2.7.1-2.7.3, 2.7.5-2.7.6 Textbook 3.6.1-3.6.5 2 Control Flow The flow of control is the sequence of instruction
More informationCPSC 213. Introduction to Computer Systems. Dynamic Control Flow Polymorphism and Switch Statements. Unit 1f
CPSC 213 Introduction to Computer Systems Unit 1f Dynamic Control Flow Polymorphism and Switch Statements 1 Readings for Next Two Lectures Text Switch Statements, Understanding Pointers - 2nd ed: 3.6.7,
More informationCPSC 213. Introduction to Computer Systems. Procedures and the Stack. Unit 1e
CPSC 213 Introduction to Computer Systems Unit 1e Procedures and the Stack 1 Readings for Next 3 Lectures Textbook Procedures - 3.7 Out-of-Bounds Memory References and Buffer Overflow - 3.12 2 Local Variables
More informationCPSC 213. Introduction to Computer Systems. Procedures and the Stack. Unit 1e
CPSC 213 Introduction to Computer Systems Unit 1e Procedures and the Stack Readings for Next 3 Lectures Textbook Procedures - 3.7 Out-of-Bounds Memory References and Buffer Overflow - 3.12 Local Variables
More informationPractical Malware Analysis
Practical Malware Analysis Ch 4: A Crash Course in x86 Disassembly Revised 1-16-7 Basic Techniques Basic static analysis Looks at malware from the outside Basic dynamic analysis Only shows you how the
More informationECE 264 Exam 2. 6:30-7:30PM, March 9, You must sign here. Otherwise you will receive a 1-point penalty.
ECE 264 Exam 2 6:30-7:30PM, March 9, 2011 I certify that I will not receive nor provide aid to any other student for this exam. Signature: You must sign here. Otherwise you will receive a 1-point penalty.
More informationWeek 9 Part 1. Kyle Dewey. Tuesday, August 28, 12
Week 9 Part 1 Kyle Dewey Overview Dynamic allocation continued Heap versus stack Memory-related bugs Exam #2 Dynamic Allocation Recall... Dynamic memory allocation allows us to request memory on the fly
More informationCSIS1120A. 10. Instruction Set & Addressing Mode. CSIS1120A 10. Instruction Set & Addressing Mode 1
CSIS1120A 10. Instruction Set & Addressing Mode CSIS1120A 10. Instruction Set & Addressing Mode 1 Elements of a Machine Instruction Operation Code specifies the operation to be performed, e.g. ADD, SUB
More informationECE264 Spring 2013 Final Exam, April 30, 2013
ECE264 Spring 2013 Final Exam, April 30, 2013 In signing this statement, I hereby certify that the work on this exam is my own and that I have not copied the work of any other student while completing
More informationCPSC 213. Introduction to Computer Systems. Procedures and the Stack. Unit 1e
CPSC 213 Introduction to Computer Systems Unit 1e Procedures and the Stack 1 Reading Companion 2.8 Textbook Procedures, Out-of-Bounds Memory References and Buffer Overflows 3.7, 3.12 2 Local Variables
More informationComputer Systems Organization V Fall 2009
Computer Systems Organization V22.0201 Fall 2009 Sample Midterm Exam ANSWERS 1. True/False. Circle the appropriate choice. (a) T (b) F At most one operand of an x86 assembly instruction can be an memory
More informationCSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community
CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community http://csc.cs.rit.edu History and Evolution of Programming Languages 1. Explain the relationship between machine
More informationCS24 Week 2 Lecture 1
CS24 Week 2 Lecture 1 Kyle Dewey Overview C Review Void pointers Allocation structs void* (Void Pointers) void* Like any other pointer, it refers to some memory address However, it has no associated type,
More informationC Review. MaxMSP Developers Workshop Summer 2009 CNMAT
C Review MaxMSP Developers Workshop Summer 2009 CNMAT C Syntax Program control (loops, branches): Function calls Math: +, -, *, /, ++, -- Variables, types, structures, assignment Pointers and memory (***
More informationCNIT 127: Exploit Development. Ch 1: Before you begin. Updated
CNIT 127: Exploit Development Ch 1: Before you begin Updated 1-14-16 Basic Concepts Vulnerability A flaw in a system that allows an attacker to do something the designer did not intend, such as Denial
More informationIntroduction to C. Why C? Difference between Python and C C compiler stages Basic syntax in C
Final Review CS304 Introduction to C Why C? Difference between Python and C C compiler stages Basic syntax in C Pointers What is a pointer? declaration, &, dereference... Pointer & dynamic memory allocation
More informationComputer System Architecture
CSC 203 1.5 Computer System Architecture Department of Statistics and Computer Science University of Sri Jayewardenepura Addressing 2 Addressing Subject of specifying where the operands (addresses) are
More informationMemory Management. a C view. Dr Alun Moon KF5010. Computer Science. Dr Alun Moon (Computer Science) Memory Management KF / 24
Memory Management a C view Dr Alun Moon Computer Science KF5010 Dr Alun Moon (Computer Science) Memory Management KF5010 1 / 24 The Von Neumann model Memory Architecture One continuous address space Program
More informationCOP 3223 Introduction to Programming with C - Study Union - Fall 2017
COP 3223 Introduction to Programming with C - Study Union - Fall 2017 Chris Marsh and Matthew Villegas Contents 1 Code Tracing 2 2 Pass by Value Functions 4 3 Statically Allocated Arrays 5 3.1 One Dimensional.................................
More informationCSE 30 Fall 2013 Final Exam
Login: cs30x Student ID Name Signature By filling in the above and signing my name, I confirm I will complete this exam with the utmost integrity and in accordance with the Policy on Integrity of Scholarship.
More informationFinal CSE 131B Spring 2004
Login name Signature Name Student ID Final CSE 131B Spring 2004 Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 Page 7 Page 8 (25 points) (24 points) (32 points) (24 points) (28 points) (26 points) (22 points)
More informationSOEN228, Winter Revision 1.2 Date: October 25,
SOEN228, Winter 2003 Revision 1.2 Date: October 25, 2003 1 Contents Flags Mnemonics Basic I/O Exercises Overview of sample programs 2 Flag Register The flag register stores the condition flags that retain
More informationCSE351 Winter 2016, Final Examination March 16, 2016
CSE351 Winter 2016, Final Examination March 16, 2016 Please do not turn the page until 2:30. Rules: The exam is closed-book, closed-note, etc. Please stop promptly at 4:20. There are 125 (not 100) points,
More informationECE264 Fall 2013 Exam 3, November 20, 2013
ECE264 Fall 2013 Exam 3, November 20, 2013 In signing this statement, I hereby certify that the work on this exam is my own and that I have not copied the work of any other student while completing it.
More informationCPSC 313, Summer 2013 Final Exam Date: June 24, 2013; Instructor: Mike Feeley
CPSC 313, Summer 2013 Final Exam Date: June 24, 2013; Instructor: Mike Feeley This is a closed-book exam. No outside notes. Electronic calculators are permitted. You may remove the last two pages of the
More informationCSE 30 Winter 2014 Final Exam
Signature Login: cs30x Name Student ID By filling in the above and signing my name, I confirm I will complete this exam with the utmost integrity and in accordance with the Policy on Integrity of Scholarship.
More informationChapter 2 (Dynamic variable (i.e. pointer), Static variable)
Chapter 2 (Dynamic variable (i.e. pointer), Static variable) August_04 A2. Identify and explain the error in the program below. [4] #include int *pptr; void fun1() { int num; num=25; pptr= #
More informationCSC 438 Systems and Software Security, Spring 2014 Instructor: Dr. Natarajan Meghanathan Question Bank for Module 6: Software Security Attacks
CSC 438 Systems and Software Security, Spring 2014 Instructor: Dr. Natarajan Meghanathan Question Bank for Module 6: Software Security Attacks 1) What will be the output of the following C program when
More informationSample Examination. Family Name:... Other Names:... Signature:... Student Number:...
Family Name:... Other Names:... Signature:... Student Number:... THE UNIVERSITY OF NEW SOUTH WALES SCHOOL OF COMPUTER SCIENCE AND ENGINEERING Sample Examination COMP1917 Computing 1 EXAM DURATION: 2 HOURS
More informationCPSC 213. Introduction to Computer Systems. Course Review. Unit 3
CPSC 213 Introduction to Computer Systems Unit 3 Course Review 1 Learning Goals 1 Memory Endianness and memory-address alignment Globals Machine model for access to global variables; static and dynamic
More informationSystems Programming and Computer Architecture ( )
Systems Group Department of Computer Science ETH Zürich Systems Programming and Computer Architecture (252-0061-00) Timothy Roscoe Herbstsemester 2016 1 4: Pointers Computer Architecture and Systems Programming
More informationUW CSE 351, Winter 2013 Midterm Exam
Full Name: Student ID: UW CSE 351, Winter 2013 Midterm Exam February 15, 2013 Instructions: Make sure that your exam is not missing any of the 9 pages, then write your full name and UW student ID on the
More informationCPSC 213. Introduction to Computer Systems. Threads. Unit 2b
CPSC 213 Introduction to Computer Systems Unit 2b Threads 1 Reading Text Concurrent Programming with Threads 2ed: 12.3 1ed: 13.3 2 The Virtual Processor Originated with Edsger Dijkstra in the THE Operating
More informationPOINTER AND ARRAY SUNU WIBIRAMA
POINTER AND ARRAY SUNU WIBIRAMA Presentation Outline Basic Pointer Arrays Dynamic Memory Allocation Basic Pointer 3 Pointers A pointer is a reference to another variable (memory location) in a program
More informationC Programming. Course Outline. C Programming. Code: MBD101. Duration: 10 Hours. Prerequisites:
C Programming Code: MBD101 Duration: 10 Hours Prerequisites: You are a computer science Professional/ graduate student You can execute Linux/UNIX commands You know how to use a text-editing tool You should
More informationDepartment of Electrical Engineering and Computer Sciences Spring 2013 Instructor: Dr. Dan Garcia CS61C Midterm
University of California, Berkeley College of Engineering Department of Electrical Engineering and Computer Sciences Spring 2013 Instructor: Dr. Dan Garcia 2013-03-04 CS61C Midterm After the exam, indicate
More informationECE 15B COMPUTER ORGANIZATION
ECE 15B COMPUTER ORGANIZATION Lecture 13 Strings, Lists & Stacks Announcements HW #3 Due next Friday, May 15 at 5:00 PM in HFH Project #2 Due May 29 at 5:00 PM Project #3 Assigned next Thursday, May 19
More informationMemory. Globals. Pointers. Dynamic Storage. If and Loop. Procedures. Not Covered on Final
Learning Goals 1 Memory CPSC 213 Endianness and memory-address alignment Globals Machine model for access to global variables; static and dynamic arrays and structs Pointers Pointers in C, & and * operators,
More informationCMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 14, FALL 2012
CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 14, FALL 2012 TOPICS TODAY Midterm exam topics Recap arrays vs pointers Characters & strings & pointers (Oh My!) Structs & pointers
More informationa data type is Types
Pointers Class 2 a data type is Types Types a data type is a set of values a set of operations defined on those values in C++ (and most languages) there are two flavors of types primitive or fundamental
More informationFundamental of Programming (C)
Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 9 Pointer Department of Computer Engineering 1/46 Outline Defining and using Pointers
More informationCOP 3223 Introduction to Programming with C - Study Union - Spring 2018
COP 3223 Introduction to Programming with C - Study Union - Spring 2018 Chris Marsh and Matthew Villegas Contents 1 Code Tracing 2 2 Pass by Value Functions 4 3 Statically Allocated Arrays 5 3.1 One Dimensional.................................
More informationFinal Exam. 11 May 2018, 120 minutes, 26 questions, 100 points
Name: CS520 Final Exam 11 May 2018, 120 minutes, 26 questions, 100 points The exam is closed book and notes. Please keep all electronic devices turned off and out of reach. Note that a question may require
More informationMIPS Functions and Instruction Formats
MIPS Functions and Instruction Formats 1 The Contract: The MIPS Calling Convention You write functions, your compiler writes functions, other compilers write functions And all your functions call other
More informationCS 61C: Great Ideas in Computer Architecture C Pointers. Instructors: Vladimir Stojanovic & Nicholas Weaver
CS 61C: Great Ideas in Computer Architecture C Pointers Instructors: Vladimir Stojanovic & Nicholas Weaver http://inst.eecs.berkeley.edu/~cs61c/sp16 1 Agenda Pointers Arrays in C 2 Address vs. Value Consider
More informationAgenda. Peer Instruction Question 1. Peer Instruction Answer 1. Peer Instruction Question 2 6/22/2011
CS 61C: Great Ideas in Computer Architecture (Machine Structures) Introduction to C (Part II) Instructors: Randy H. Katz David A. Patterson http://inst.eecs.berkeley.edu/~cs61c/sp11 Spring 2011 -- Lecture
More informationCSE 351 Midterm Exam
University of Washington Computer Science & Engineering Winter 2018 Instructor: Mark Wyse February 5, 2018 CSE 351 Midterm Exam Last Name: First Name: SOLUTIONS UW Student ID Number: UW NetID (username):
More informationC0MP1911 Final Exam 1337 Computing 1
Family Name: Other Names: Signature: Student Number: This PAPER is NOT to be retained by the STUDENT The University Of New South Wales C0MP1911 Final Exam 1337 Computing 1 July 2006 Time allowed: 3 hrs
More informationUniversity of California, Berkeley College of Engineering
University of California, Berkeley College of Engineering Department of Electrical Engineering and Computer Sciences Summer 2015 Instructor: Sagar Karandikar 2015-07-09 L J After the exam, indicate on
More informationInstruction Set Architectures Part I: From C to MIPS. Readings:
Instruction Set Architectures Part I: From C to MIPS Readings: 2.1-2.14 1 Goals for this Class Understand how CPUs run programs How do we express the computation the CPU? How does the CPU execute it? How
More informationReading. Text. Multiple things co-existing on the same physical CPU in The Structure of the THE Multiprogramming System, 1968
Reading Text CPSC 213 Concurrent Programming with Threads 2ed: 12.3 1ed: 13.3 Introduction to Computer Systems Unit 2b Threads The Virtual Processor 1 Illusion of Synchrony 2 Originated with Edsger Dijkstra
More informationLearning Goals 2. Static and dynamic Endianness and memory-address alignment. Read Assembly. Write Assembly. ISA-PL Connection.
Learning Goals Learning Goals Big Ideas: First Half Read Static and dynamic Endianness and memory-address alignment CPSC Read assembly code Globals model for access to global variables; static and dynamic
More informationComputer Architecture I Midterm I
Computer Architecture I Midterm I April 11 2017 Computer Architecture I Midterm I Chinese Name: Pinyin Name: E-Mail... @shanghaitech.edu.cn: Question Points Score 1 1 2 12 3 16 4 14 5 18 6 17 7 22 Total:
More informationEE319K Exam 1 Summer 2014 Page 1. Exam 1. Date: July 9, Printed Name:
EE319K Exam 1 Summer 2014 Page 1 Exam 1 Date: July 9, 2014 UT EID: Printed Name: Last, First Your signature is your promise that you have not cheated and will not cheat on this exam, nor will you help
More informationWhen you add a number to a pointer, that number is added, but first it is multiplied by the sizeof the type the pointer points to.
Refresher When you add a number to a pointer, that number is added, but first it is multiplied by the sizeof the type the pointer points to. i.e. char *ptr1 = malloc(1); ptr1 + 1; // adds 1 to pointer
More informationComputer Architecture I Mid-Term I
Computer Architecture I Mid-Term I April 19 2018 Computer Architecture I Mid-Term I Chinese Name: Pinyin Name: E-Mail... @shanghaitech.edu.cn: Question Points Score 1 1 2 11 3 10 4 9 5 14 6 29 7 14 8 12
More informationComputer Systems Lecture 9
Computer Systems Lecture 9 CPU Registers in x86 CPU status flags EFLAG: The Flag register holds the CPU status flags The status flags are separate bits in EFLAG where information on important conditions
More informationPart 1 (70% of grade for homework 2): MIPS Programming: Simulating a simple computer
CS 465 - Homework 2 Fall 2016 Profs. Daniel A. Menasce and Yutao Zhong Team Allowed: maximum of two per team. State clearly team member names and GMU IDs as comments in source code and each page of submitted
More informationC Introduction. Comparison w/ Java, Memory Model, and Pointers
CS 261 Fall 2018 Mike Lam, Professor C Introduction Comparison w/ Java, Memory Model, and Pointers Please go to socrative.com on your phone or laptop, choose student login and join room LAMJMU The C Language
More informationCSE 30 Fall 2012 Final Exam
Login: cs30x Student ID Name Signature By filling in the above and signing my name, I confirm I will complete this exam with the utmost integrity and in accordance with the Policy on Integrity of Scholarship.
More informationProcesses. Johan Montelius KTH
Processes Johan Montelius KTH 2017 1 / 47 A process What is a process?... a computation a program i.e. a sequence of operations a set of data structures a set of registers means to interact with other
More informationSubject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100
Code: DC-05 Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100 NOTE: There are 11 Questions in all. Question 1 is compulsory and carries 16 marks. Answer to Q. 1. must be written in the space
More informationQ1: /8 Q2: /30 Q3: /30 Q4: /32. Total: /100
ECE 2035(A) Programming for Hardware/Software Systems Fall 2013 Exam Three November 20 th 2013 Name: Q1: /8 Q2: /30 Q3: /30 Q4: /32 Total: /100 1/10 For functional call related questions, let s assume
More informationA process. the stack
A process Processes Johan Montelius What is a process?... a computation KTH 2017 a program i.e. a sequence of operations a set of data structures a set of registers means to interact with other processes
More informationECE 2035 Programming HW/SW Systems Fall problems, 5 pages Exam Three 20 November 2013
Instructions: This is a closed book, closed note exam. Calculators are not permitted. If you have a question, raise your hand and I will come to you. Please work the exam in pencil and do not separate
More informationCS , Fall 2007 Exam 1
Andrew login ID: Full Name: CS 15-213, Fall 2007 Exam 1 Wednesday October 17, 2007 Instructions: Make sure that your exam is not missing any sheets, then write your full name and Andrew login ID on the
More informationReview: C Strings. A string in C is just an array of characters. Lecture #4 C Strings, Arrays, & Malloc
CS61C L4 C Pointers (1) inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture #4 C Strings, Arrays, & Malloc Albert Chae Instructor 2008-06-26 Review: C Strings A string in C is just an array
More informationECE 2035 Programming Hw/Sw Systems Spring problems, 8 pages Final Exam Solutions 1 May 2013
Problem 1 (3 parts, 30 points) Compilation, Concurrency & Interrupts Part A (20 points) Perform at least five standard compiler optimizations on the following C code fragment by writing the optimized version
More informationCA341 - Comparative Programming Languages
CA341 - Comparative Programming Languages David Sinclair Dynamic Data Structures Generally we do not know how much data a program will have to process. There are 2 ways to handle this: Create a fixed data
More informationLecture Notes Companion CPSC 213
Lecture Notes Companion CPSC 213 2 nd Edition DRAFT Oct28 Mike Feeley University of British Columbia February 13, 2012 2 Contents 1 Introduction to the Computer Systems 7 1.1 Java and C.................................................
More informationMachine Language Instructions Introduction. Instructions Words of a language understood by machine. Instruction set Vocabulary of the machine
Machine Language Instructions Introduction Instructions Words of a language understood by machine Instruction set Vocabulary of the machine Current goal: to relate a high level language to instruction
More informationPointers (2) Applications
Pointers (2) Applications December 9, 2017 This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported license. 0.1 const qaulifier t1.c #include #include
More informationCENG3420 Lecture 03 Review
CENG3420 Lecture 03 Review Bei Yu byu@cse.cuhk.edu.hk 2017 Spring 1 / 38 CISC vs. RISC Complex Instruction Set Computer (CISC) Lots of instructions of variable size, very memory optimal, typically less
More informationCSCE 5610: Computer Architecture
HW #1 1.3, 1.5, 1.9, 1.12 Due: Sept 12, 2018 Review: Execution time of a program Arithmetic Average, Weighted Arithmetic Average Geometric Mean Benchmarks, kernels and synthetic benchmarks Computing CPI
More informationCSci 4061 Introduction to Operating Systems. Programs in C/Unix
CSci 4061 Introduction to Operating Systems Programs in C/Unix Today Basic C programming Follow on to recitation Structure of a C program A C program consists of a collection of C functions, structs, arrays,
More informationLecture 03 Bits, Bytes and Data Types
Lecture 03 Bits, Bytes and Data Types Computer Languages A computer language is a language that is used to communicate with a machine. Like all languages, computer languages have syntax (form) and semantics
More informationIn Java we have the keyword null, which is the value of an uninitialized reference type
+ More on Pointers + Null pointers In Java we have the keyword null, which is the value of an uninitialized reference type In C we sometimes use NULL, but its just a macro for the integer 0 Pointers are
More informationIMPORTANT QUESTIONS IN C FOR THE INTERVIEW
IMPORTANT QUESTIONS IN C FOR THE INTERVIEW 1. What is a header file? Header file is a simple text file which contains prototypes of all in-built functions, predefined variables and symbolic constants.
More informationProgramming in C - Part 2
Programming in C - Part 2 CPSC 457 Mohammad Reza Zakerinasab May 11, 2016 These slides are forked from slides created by Mike Clark Where to find these slides and related source code? http://goo.gl/k1qixb
More informationCS 3330 Exam 3 Fall 2017 Computing ID:
S 3330 Fall 2017 Exam 3 Variant E page 1 of 16 Email I: S 3330 Exam 3 Fall 2017 Name: omputing I: Letters go in the boxes unless otherwise specified (e.g., for 8 write not 8 ). Write Letters clearly: if
More information2. ADDRESSING METHODS
2 Addressing Methods STUDY MATERIALS ON COMPUTER ORGANIZATION (As per the curriculum of Third semester BSc Electronics of Mahatma Gandh Uniiversity) Compiled by Sam Kollannore U Lecturer in Electronics
More informationCS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor
CS 261 Fall 2017 Mike Lam, Professor C Introduction Variables, Memory Model, Pointers, and Debugging The C Language Systems language originally developed for Unix Imperative, compiled language with static
More informationCommon Misunderstandings from Exam 1 Material
Common Misunderstandings from Exam 1 Material Kyle Dewey Stack and Heap Allocation with Pointers char c = c ; char* p1 = malloc(sizeof(char)); char** p2 = &p1; Where is c allocated? Where is p1 itself
More informationThis simulated machine consists of four registers that will be represented in your software with four global variables.
CSCI 4717 Computer Architecture Project 1: Two-Stage Instuction Decoder Due: Monday, September 21, 26 at 11:59 PM What to submit: You will be submitting a text file containing two C functions, fetchnextinstruction()
More information