Midterm Sample Questions. a) What evaluates to FALSE in C? What evaluates to TRUE?

Similar documents
University of California, San Diego CSE 30 Computer Organization and Systems Programming Winter 2014 Midterm Dr. Diba Mirza

11 'e' 'x' 'e' 'm' 'p' 'l' 'i' 'f' 'i' 'e' 'd' bool equal(const unsigned char pstr[], const char *cstr) {

C Programming. Course Outline. C Programming. Code: MBD101. Duration: 10 Hours. Prerequisites:

Lecture 8: Pointer Arithmetic (review) Endianness Functions and pointers

Lecture 12 Integers. Computer and Network Security 19th of December Computer Science and Engineering Department

Introduction to C. Why C? Difference between Python and C C compiler stages Basic syntax in C

Portland State University. CS201 Section 5. Midterm Exam. Fall 2018

Introduction to C Language (M3-R )

CSCI 2212: Intermediate Programming / C Review, Chapters 10 and 11

C++ ARRAYS POINTERS POINTER ARITHMETIC. Problem Solving with Computers-I

Contents of Lecture 3

2. MACHINE REPRESENTATION OF TYPICAL ARITHMETIC DATA FORMATS (NATURAL AND INTEGER NUMBERS).

a) Write the signed (two s complement) binary number in decimal: b) Write the unsigned binary number in hexadecimal:

Chapter 2. Instruction Set. RISC vs. CISC Instruction set. The University of Adelaide, School of Computer Science 18 September 2017

Today s lecture. Pointers/arrays. Stack versus heap allocation CULTURE FACT: IN CODE, IT S NOT CONSIDERED RUDE TO POINT.

Week 8 Lecture 3. Finishing up C

Midterm Exam Review Slides

Page 1. Where Have We Been? Chapter 2 Representing and Manipulating Information. Why Don t Computers Use Base 10?

INITIALISING POINTER VARIABLES; DYNAMIC VARIABLES; OPERATIONS ON POINTERS

Lecture 5: Outline. I. Multi- dimensional arrays II. Multi- level arrays III. Structures IV. Data alignment V. Linked Lists

First of all, it is a variable, just like other variables you studied

Computer Systems Programming. Practice Midterm. Name:

Section Notes - Week 1 (9/17)

advanced data types (2) typedef. today advanced data types (3) enum. mon 23 sep 2002 defining your own types using typedef

Aryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9

Survey. Motivation 29.5 / 40 class is required

Computer Organization & Systems Exam I Example Questions

Time: 8:30-10:00 pm (Arrive at 8:15 pm) Location What to bring:

Lecture 4: Outline. Arrays. I. Pointers II. III. Pointer arithmetic IV. Strings

CS 61c: Great Ideas in Computer Architecture

CYSE 411/AIT681 Secure Software Engineering Topic #10. Secure Coding: Integer Security

THE GOOD, BAD AND UGLY ABOUT POINTERS. Problem Solving with Computers-I

2/9/18. Readings. CYSE 411/AIT681 Secure Software Engineering. Introductory Example. Secure Coding. Vulnerability. Introductory Example.

2/9/18. CYSE 411/AIT681 Secure Software Engineering. Readings. Secure Coding. This lecture: String management Pointer Subterfuge

Lecture 2: C Programm

CIS 2107 Computer Systems and Low-Level Programming Fall 2011 Midterm

Multidimension array, array of strings

ECE 250 / CS 250 Computer Architecture. C to Binary: Memory & Data Representations. Benjamin Lee

Intro to C: Pointers and Arrays

Under the Hood: Data Representations, Memory and Bit Operations. Computer Science 104 Lecture 3

COMP2611: Computer Organization. Data Representation

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

We would like to find the value of the right-hand side of this equation. We know that

CSE 509: Computer Security

Lecture 14. No in-class files today. Homework 7 (due on Wednesday) and Project 3 (due in 10 days) posted. Questions?

CS61c Summer 2014 Midterm Exam

17. Instruction Sets: Characteristics and Functions

Do not start the test until instructed to do so!

Dynamic Memory Allocation

Malloc Lab & Midterm Solutions. Recitation 11: Tuesday: 11/08/2016

Code No: R Set No. 1

CS 61C: Great Ideas in Computer Architecture. (Brief) Review Lecture

Announcements. assign0 due tonight. Labs start this week. No late submissions. Very helpful for assign1

CSCI 262 Data Structures. Arrays and Pointers. Arrays. Arrays and Pointers 2/6/2018 POINTER ARITHMETIC

Final Exam. 11 May 2018, 120 minutes, 26 questions, 100 points

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

Problem 2 Add the two 2 s complement signed 8-bit values given below, and express your answer in decimal.

CS 61C: Great Ideas in Computer Architecture C Pointers. Instructors: Vladimir Stojanovic & Nicholas Weaver

Pointers (part 1) What are pointers? EECS We have seen pointers before. scanf( %f, &inches );! 25 September 2017

CSCI 6610: Review. Chapter 7: Numbers Chapter 8: Characters Chapter 11 Pointers

211: Computer Architecture Summer 2016

C Programming Basics II

Representation of Information

Topics Power tends to corrupt; absolute power corrupts absolutely. Computer Organization CS Data Representation

Lecture 3: C Programm

But first, encode deck of cards. Integer Representation. Two possible representations. Two better representations WELLESLEY CS 240 9/8/15

Lectures 5-6: Introduction to C

CMPSC 311 Exam 2. March 27, 2015

Data Representation and Storage. Some definitions (in C)

Intermediate Programming, Spring 2017*

Character Strings. String-copy Example

Pointers. Memory. void foo() { }//return

Arrays and Memory Management

MIPS Assembly: Practice Questions for Midterm 1 Saving to and Loading from Memory CS 64: Computer Organization and Design Logic Lecture #6

Midterm Review. CS 211 Fall 2018

CS61, Fall 2012 Midterm Review Section

Chapter 2. Instructions: Language of the Computer. Adapted by Paulo Lopes

Computer System and programming in C

Practical Malware Analysis

ICS Instructor: Aleksandar Kuzmanovic TA: Ionut Trestian Recitation 2

Midterm 1 topics (in one slide) Bits and bitwise operations. Outline. Unsigned and signed integers. Floating point numbers. Number representation

Numbers: positional notation. CS61C Machine Structures. Faux Midterm Review Jaein Jeong Cheng Tien Ee. www-inst.eecs.berkeley.

CS107 Handout 13 Spring 2008 April 18, 2008 Computer Architecture: Take II

Lectures 5-6: Introduction to C

Outline. Classic races: files in /tmp. Race conditions. TOCTTOU example. TOCTTOU gaps. Vulnerabilities in OS interaction

ME964 High Performance Computing for Engineering Applications

Time (self-scheduled): Location Schedule Your Exam: What to bring:

CSCI 2212: Intermediate Programming / C Chapter 15

CS61C Machine Structures. Lecture 4 C Pointers and Arrays. 1/25/2006 John Wawrzynek. www-inst.eecs.berkeley.edu/~cs61c/

A few examples are below. Checking your results in decimal is the easiest way to verify you ve got it correct.

In Java we have the keyword null, which is the value of an uninitialized reference type

Binary Representations and Arithmetic

Run time environment of a MIPS program

Dynamic memory. EECS 211 Winter 2019

CSE351 Spring 2018, Midterm Exam April 27, 2018

Bits and Bytes. Why bits? Representing information as bits Binary/Hexadecimal Byte representations» numbers» characters and strings» Instructions

CSE351 Spring 2018, Final Exam June 6, 2018

Pointers, Dynamic Data, and Reference Types

Objects and Types. COMS W1007 Introduction to Computer Science. Christopher Conway 29 May 2003

A Java program contains at least one class definition.

Transcription:

Midterm Syllabus: 1. Number systems a. Signed and unsigned representations b. Conversion between different representations c. Overflow condition 2. C Pointers 3. Dynamic Memory Allocation 4. C Data structures: Arrays, structs, multi-dimensional and multi-level arrays 5. Data in memory a. Endian-ness b. Heap or Stack? c. Data alignment 6. ARM ISA basics 7. ARM arithmetic and bitwise instructions Section 1: Short Answers Midterm Sample Questions a) What evaluates to FALSE in C? What evaluates to TRUE? b) How do dynamically allocated data objects and local variables differ in terms of their lifetime? c) What is a dangling pointer? d) Give one example for i) type promotion and ii) type truncation in C. e) How is a multi-level array different from a multi-dimensional array? f) What do RISC and CISC stand for? Explain at least one difference between them. 1

2) Section 2: Number Representation There are 256 ways to personalize a Wendy s burger (5 points) How many yes/no options (e.g., mustard/no mustard, lettuce/no lettuce, etc.) do you have to personalize your Wendy s hamburger? (5 points) If Wendy s added two additional yes/no options, how many total ways would one now have to personalize your Wendy s burger? Assume that these two options are totally independent of the 256 current ways of personalization. (5 points) Assume that In-N-Out has N ways to personalize their burger. How many bits do they require to represent all of these personalization options? (5 points) Knowing the secret In-N-Out menu expands the number of options by 17 times, i.e., there are 17N ways to personalize your burger if you know the secret menu options. How many bits does this require? How many qubits does this require? (Remember a qubit can have one of three states) (15 points) Write the Condition bits for the following calculations (8-bit two s complement numbers) 01101010 10110110 + ------------ 00111100 01010110 - ------------ 10001011 01110110 + ------------ Negative: Zero: Overflow: Carry: Negative: Zero: Overflow: Carry: Negative: Zero: Overflow: Carry: 2

(10 points) Deduce logically the condition bits (NZVC) for the following arithmetic operation: 54 10 278 10 when a 64-bit 2 s compliment format is used. You should not try to do the actual bitwise subtraction. Section 3: Pointers and arrays Q1: For parts a) and b) assume the following: I. The byte ordering is Little Endian II. The address of the first element of the array arr is 0x00 III. short is 2 bytes. a) (10 points) Using a diagram show the byte level arrangement of the elements of the array arr in memory. Use a hex format to represent the values stored in each byte of memory. What is the value of *(*(arr+1)+1)? short arr[2][3]={{0x01,0x02,0x03,{0x04,0x05,0x06; b) (5 points) Consider the following C code 3

void print_elements (int i) { int j; short arr[3]={0x01,0x02,0x03; char *ptr = (char *) arr; for (j=0; j<=i; j++) printf ( \n %x,,*(ptr+j)); What is the output when print_elements is called with an argument of 4 i.e.: print_elements(4); Q2: More fun with pointers For the C code below make the following assumptions i. The base address of array is 0x10000000 ii. The byte ordering is Little Endian iii. int is 4 bytes int array[5]={-1,1,2,3,4,5; int main(){ char *ptr1 = (((char *) array) + 5); char val; int *ptr2 = array + 3; val = *ptr1; return 0; i) (10 points) Show the byte level representation of array in memory. You have to mark the increasing direction of memory addresses. ii) (5 points) What is the value in *ptr2 at the end of the program? iii) (5 points) What is the value of the variable val at the end of the program? Q3: (10 points) Draw a diagram to show the final relationship between pointers and pointees and the values in the array arr when the following code is executed main() { 4

char *p, *q; char arr[]= Doing well! Keep it up ; p =arr; q = arr+4; p=q; *q = *(p+1); Q4: C Strings: Consider the following definition of the function append. /* Return the result of appending the characters in the string s2 to the string s1. Assume enough space has been allocated for s1 to store the extra characters. */ char* append (char s1[ ], char s2[ ]) { int s1len = strlen (s1); int s2len = strlen (s2); int k; for (k=0; k<s2len; k++) { s1[k+s1len+1] = s2[k]; return s1; There are two bugs in the above code. Identify them. Explain why they are bugs and modify the code to correct them. Q6: Dynamic Memory allocation: Consider the following declaration for the multi-level array, names: char name_1[]= John ; char name_2[]= Paul ; char name_3[] = Stephen ; char *names[3]={name_1, name_2, name_3; Create an equivalent multi-level array: dynamic_names that has all its elements and the data pointed to by its elements on the heap. Section 4: ARM Arithmetic and Bitwise 5

Q1: (5 points) Perform the following multiply operation by writing one or more instructions in ARM. Assume the required inputs are available in registers. Use the following variable to register mapping in all cases: x: r0, y: r1. Multiply x by 25 10 and store the result in y (Don t use the MUL/MLA instructions). How many bytes does your code need? Q2: (15 points, 10 minutes) Copy the most significant byte of the variable y into the least significant byte of the variable x. All other bits in x should remain unchanged. For example, if x has the initial value 0x83123456 and y has the value 0xFE128A20, x should change to 0x831234FE. Assume the variable x is mapped to register r0, y is mapped to register r1. You can use other registers to store intermediate results. Comment each line. How many bytes does your code need? 6