CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

Similar documents
Expressions and Precedence. Last updated 12/10/18

Information Science 1

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

C/Java Syntax. January 13, Slides by Mark Hancock (adapted from notes by Craig Schock)

C/Java Syntax. Lecture 02 Summary. Keywords Variable Declarations Data Types Operators Statements. Functions. if, switch, while, do-while, for

Lecture 02 Summary. C/Java Syntax 1/14/2009. Keywords Variable Declarations Data Types Operators Statements. Functions

Review of the C Programming Language for Principles of Operating Systems

Operators. Java operators are classified into three categories:

Computers Programming Course 6. Iulian Năstac

Operators in C. Staff Incharge: S.Sasirekha

DEPARTMENT OF MATHS, MJ COLLEGE

Fundamental of Programming (C)

Review of the C Programming Language

A flow chart is a graphical or symbolic representation of a process.

Fundamentals of Programming

A complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g.

UNIT- 3 Introduction to C++

Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands

QUIZ: What value is stored in a after this

Recap. ANSI C Reserved Words C++ Multimedia Programming Lecture 2. Erwin M. Bakker Joachim Rijsdam

6.096 Introduction to C++ January (IAP) 2009

.Net Technologies. Components of.net Framework

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

SECTION II: LANGUAGE BASICS

GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one.

C OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure

QUIZ. 1. Explain the meaning of the angle brackets in the declaration of v below:

C OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed

CSC 1214: Object-Oriented Programming

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

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

C: How to Program. Week /Mar/05

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal


Chapter 2 - Introduction to C Programming

Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan

Introduction to Programming

ISA 563 : Fundamentals of Systems Programming

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

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

Operators & Expressions

Infix to Postfix Conversion

Lecture 02 C FUNDAMENTALS

Informatics Ingeniería en Electrónica y Automática Industrial

Main Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

JAVA OPERATORS GENERAL

Embedded Controller Programming 2

Programming Fundamentals - A Modular Structured Approach using C++ By: Kenneth Leroy Busbee

Quick Reference Guide

Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators

CHW 469 : Embedded Systems

Introduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan

Pointers, Dynamic Data, and Reference Types

QUIZ How do we implement run-time constants and. compile-time constants inside classes?

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

BLM2031 Structured Programming. Zeyneb KURT

EL6483: Brief Overview of C Programming Language

Chapter 12 Variables and Operators

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

CENG 447/547 Embedded and Real-Time Systems. Review of C coding and Soft Eng Concepts

Why embedded systems?

UNIVERSITY OF LIMERICK OLLSCOIL LUIMNIGH COLLEGE OF INFORMATICS & ELECTRONICS DEPARTMENT OF ELECTRONIC & COMPUTER ENGINEERING

CS313D: ADVANCED PROGRAMMING LANGUAGE

Variables and literals

Programming and Data Structures

Introduction to C++ Introduction. Structure of a C++ Program. Structure of a C++ Program. C++ widely-used general-purpose programming language

MPATE-GE 2618: C Programming for Music Technology. Syllabus

C-LANGUAGE CURRICULAM

Java Basic Programming Constructs

Introduction to C++ with content from

Homework #3 CS2255 Fall 2012

Lecture 3. More About C

Chapter 7. Additional Control Structures

Unit 3. Operators. School of Science and Technology INTRODUCTION

Part I Part 1 Expressions

Writing Program in C Expressions and Control Structures (Selection Statements and Loops)

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

I2204 ImperativeProgramming Semester: 1 Academic Year: 2018/2019 Credits: 5 Dr Antoun Yaacoub

OBJECT ORIENTED PROGRAMMING

Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators

Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and

P.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above

Unit-2 (Operators) ANAND KR.SRIVASTAVA

DETAILED SYLLABUS INTRODUCTION TO C LANGUAGE

Structures, Operators

Tokens, Expressions and Control Structures

Understanding Pointers

Unit-II Programming and Problem Solving (BE1/4 CSE-2)

Embedded Systems. Introduction. The C Language. Introduction. Why C instead ASM. Introduction to C Embedded Programming language

Arrays, Pointers and Memory Management

C Syntax Arrays and Loops Math Strings Structures Pointers File I/O. Final Review CS Prof. Jonathan Ventura. Prof. Jonathan Ventura Final Review

High Performance Computing in C and C++

Holtek C and ANSI C Feature Comparison User s Guide

Programming in C++ 5. Integral data types

CprE 288 Spring 2014 Homework 5 Due Fri. Feb. 21

2/29/2016. Definition: Computer Program. A simple model of the computer. Example: Computer Program. Data types, variables, constants

Java Notes. 10th ICSE. Saravanan Ganesh

ME 461 C review Session Fall 2009 S. Keres

Introduction to C. Systems Programming Concepts

Transcription:

CprE 288 Introduction to Embedded Systems Exam 1 Review http://class.ece.iastate.edu/cpre288 1

Overview of Today s Lecture Announcements Exam 1 Review http://class.ece.iastate.edu/cpre288 2

Announcements Exam 1: Wed 6/6, in class Open textbook, 1 page of notes, and calculator allowed 60 minutes Electronic textbook and electronic Datasheet is fine. But nothing else on your electronic device can be used or you will receive an F for CPRE 288 http://class.ece.iastate.edu/cpre288 3

EXAM FORMAT http://class.ece.iastate.edu/cpre288 4

Exam Format Focus Embedded C programming, questions specific to the labs processor Memory Mapped I/O and Registers Memory Layout Interrupts Covers material in lectures No questions about UARTs No questions about ADC Covers material in homework's Cover materials in Labs 1-4 60 points total 10% of your course grade http://class.ece.iastate.edu/cpre288 5

EXAM TOPICS http://class.ece.iastate.edu/cpre288 6

Exam Preparation Suggested preparation steps: Review homeworks Review lectures Review labs Note: this set of slides are not comprehensive http://class.ece.iastate.edu/cpre288 7

Keywords char short int long float double enum struct union break case continue default do else for goto if return switch while auto const extern register signed static unsigned volatile sizeof typedef void http://class.ece.iastate.edu/cpre288 8

Syntax Could you write the following statements by hand? Loops (for, while, do) Write a for loop to sum elements of an array or count characters in a string Do you know the syntax of a do while loop, for loop, and while loop? typedef Could you write a typedef definition Do you know what it means when you see a variable type like uint8_t? Switch statements Do you know where the semi-colon and colons go in a switch/case statement? Do you understand how the control flow can fall through a case? Control flow Do you understand the keywords break and continue and their use? http://class.ece.iastate.edu/cpre288 9

Know your Operators Do you know the difference between these two sets of operators? & ~ ^ &&! http://class.ece.iastate.edu/cpre288 10

Know your Operators char a = 20, b = 10, r = 5; // math operations r = a + b; r = a b; r = a * b; r = a \ b; r = a % b; // bitwise operators r = a & 3; r = a b; r = a ^ 0xFF; r = ~a; r = a >> 3; r = b << r; // conditional r = (r)? a : b; // boolean r = a b; r = a && b; r =!a; r = a < 20; r = b <= 15; r = b > 10; r = a >= b; // post and prefix a++; ++a; b--; --b; // assignments r = a = b = 42; r += a; r -= b; http://class.ece.iastate.edu/cpre288 11

Know how to use Operator Precedence Can you use this table? Precedence Operator Description Associativity ++ -- Suffix/postfix increment and decrement Left-to-right () Function call 1 [] Array subscripting. Element selection by reference -> Element selection through pointer ++ -- Prefix increment and decrement Right-to-left + - Unary plus and minus! ~ Logical NOT and bitwise NOT 2 (type ) Type cast * Indirection (dereference) & Address-of sizeof Size-of 3 * / % Multiplication, division, and modulus (remainder) Left-to-right 4 + - Addition and subtraction 5 << >> Bitwise left shift and right shift 6 < <= For relational operators < and respectively > >= For relational operators > and respectively 7 ==!= For relational = and respectively 8 & 9 ^ 10 11 && 12 13?: Ternary conditional Right-to-Left = Direct assignment += -= Assignment by sum and difference 14 *= /= %= Assignment by product, quotient, and remainder <<= >>= Assignment by bitwise left shift and right shift &= ^= = Assignment by bitwise AND, XOR, and OR 15, Comma Left-to-right http://class.ece.iastate.edu/cpre288 12

Know your Declarations Do these declarations make sense? void main() { char x = 5, y = 10; char z; char array1[10]; char array2[] = {1, 2, 3}; char array3[5] = {1, 2, 3}; char *str = Hello! ; } int i = 7; int *ptr = &i; int **pp = &ptr; char *p; http://class.ece.iastate.edu/cpre288 13

Know your Declarations Do these declarations make sense? struct House { unsigned long value; unsigned char baths; unsigned char bedrooms; unsigned char stories; unsigned long footage; }; void main() { struct House my_home; struct House *bob_home = &my_home; } my_home.baths = 1; my_home.value = 115000; bob_home->baths = 3; bob_home->value = 230000; http://class.ece.iastate.edu/cpre288 14

Data Structures Array access Pointers Dereference Address operator Access members of structs and unions Bit-field defined struct Know the difference between a struct and union http://class.ece.iastate.edu/cpre288 15

Pointers What are pointers Relationship between pointers array names Pointer arithmetic Be sure to review class examples and homework problems related to pointers http://class.ece.iastate.edu/cpre288 16

C-strings Review the concept of C-strings Relationship between C-strings arrays Understand the importance of the NULL byte of a C-string http://class.ece.iastate.edu/cpre288 17

Bitwise operations Forcing bits to 1 Forcing bits to 0 Testing for bits set to 1 Testing for bits cleared to 0 Generic systematic checking example if( (x & MASK_ALL1s) == MASK_ALL1 && (~x & MASK_ALL0s) == MASK_ALL0s && (x & MASK_ANY1s) && (~x & MASK_ANY0s) ) http://class.ece.iastate.edu/cpre288 18

Variable Scope Global variables Local variables Local static variables Global static variables volatile variables http://class.ece.iastate.edu/cpre288 19

Memory Mapped I/O Concept of Memory Mapped I/O Device registers can be accessed from a program as if accessing memory (i.e. devices registers are mapped to memory addresses) Allow sending commands and checking status of a devices by just reading and writing to memory mapped locations. Polling device status vs. device initiating an interrupt. http://class.ece.iastate.edu/cpre288 20

Memory Layout Stack What type of information is placed in the stack? Typically starts at the top of memory and grows downward Function s/procedure s Stack-Frame: The information placed on the stack by a function when it is called (e.g. local variables, input parameters, return address) Heap Stores dynamically allocated memory (i.e. allocated using malloc). Typically starts at a low address and grows upward Static Data segment: Region of memory where Global variables and static local variables are stored. http://class.ece.iastate.edu/cpre288 21

Interrupts What is an interrupt? An event that occurs from outside your program (e.g. Keyboard requesting service, Timer that times out, UART receiving a byte of information) What is an Interrupt Service Routine (ISR)? Code associated with a given interrupt (i.e. a given event), that executes when that interrupt occurs. What actions are taken when an interrupt occurs? Normal program execution is paused ISR execution begins Normal program execution resumes after ISR completes http://class.ece.iastate.edu/cpre288 22

Writing the Body of a function There will be 1 or 2 problems where you will be asked to write the body of a function to implement a defined computation. http://class.ece.iastate.edu/cpre288 23

Show your work Please show intermediate steps. This will help us give partial credit Write down assumptions. In general Profs/TAs will not answer questions during the test. They will just tell you to write down your assumptions The exception will be if a major typo is found by a student. http://class.ece.iastate.edu/cpre288 24

QUESTIONS http://class.ece.iastate.edu/cpre288 25

Question 1 A. How many bytes are each of the following types (on the TMC123)? char, short, int, long, float, double B. What range of values can be stored in an unsigned char? C. What range of values can be stored in a signed char? D. What is the value stored in x after this code runs? int x, y, z; x = y = z = 10; http://class.ece.iastate.edu/cpre288 26

Question 1 (answer) Name Number of Bytes sizeof() Range char 1-128 to 127 signed char 1-128 to 127 unsigned char 1 0 to 255 short 2-32,768 to 32,767 unsigned short 2 0 to 65,535 int (on TMC4123) 4-2147483648 to 2147483647 unsigned int (on TMC4123) 4 0 to 4294967295 (pointer on TMC4123) 4 Address Space long 4-2147483648 to 2147483647 signed long 4-2147483648 to 2147483647 unsigned long 4 0 to 4294967295 float 4 ±1.175e-38 to ±3.402e38 http://class.ece.iastate.edu/cpre288 27

Question 2 A. Analyze the following code: char r = 0, s = 1, t = 2; char *p1 = &s; char *p2 = &t; char **pp3 = &p1; *p1 = 10; **pp3 = 15; *p2 = 30; *pp3 = &r; **pp3 = 5; *p1 = 25; http://class.ece.iastate.edu/cpre288 28

Question 2 (answer) A. Analyze the following code: char r = 0, s = 1, t = 2; char *p1 = &s; char *p2 = &t; char **pp3 = &p1; *p1 = 10; // s = 10 **pp3 = 15; // s = 15 *p2 = 30; // t = 30 *pp3 = &r; // p1 = &r **pp3 = 5; // r = 5 *p1 = 25; // r = 25 r s t 0 1 2 0 10 2 0 15 2 0 15 30 0 15 30 5 15 30 25 15 30 http://class.ece.iastate.edu/cpre288 29

Question 3a When is the condition of the following if statement true? if ((x = 3) (x & 1)) { } // do something http://class.ece.iastate.edu/cpre288 30

Question 3a (answer) When is the condition of the following if statement true? if ((x = 3) (x & 1)) { } // do something The statement is always true. Know the difference between the assignment operator (=) and the equality operator (==). The value on the left (x = 3) is always true, as the value of an assignment is the value that was assigned. This allows programmers to have compound assignments. http://class.ece.iastate.edu/cpre288 31

Question 3b When is the condition of the following if statement true? if ((x == 3) (x & 1)) { } // do something http://class.ece.iastate.edu/cpre288 32

Question 3b (answer) When is the condition of the following if statement true? if ((x == 3) (x & 1)) { } // do something The statement is true if x is either equal to 3 or bit 0 is set. http://class.ece.iastate.edu/cpre288 33

Question 4a When is the condition of the following if statement true? if (x & 0x08 == 0x08) { } // do something http://class.ece.iastate.edu/cpre288 34

Question 4a (answer) When is the condition of the following if statement true? if (x & 0x08 == 0x08) { } // do something The statement is true if bit 0 of x is 1. Operator precedence evaluates the == operator before the bitwise AND (&). Assumes TRUE (i.e. 0x08 == 0x08) evaluates to 1 http://class.ece.iastate.edu/cpre288 35

Question 4b When is the condition of the following if statement true? if ((x & 0x08) == 0x08) { } // do something http://class.ece.iastate.edu/cpre288 36

Question 4b (answer) When is the condition of the following if statement true? if ((x & 0x08) == 0x08) { } // do something The statement is true if bit3 of x is set. x = 0b00001000; condition is TRUE x = 0b01001110; condition is TRUE x = 0b00101001; condition is TRUE x = 0b00000000; condition is FALSE x = 0b11100000; condition is FALSE http://class.ece.iastate.edu/cpre288 37

Question 6a What are the values of c1, c2, c3, and c4 after the following code executes? char myarray[3] = {1, 2, 3}; char *ptr = myarray; char c1 = *ptr++; char c2 = *ptr; char c3 = myarray[0]; char c4 = myarray[1]; http://class.ece.iastate.edu/cpre288 38

Question 6a (answer) char myarray[3] = {1, 2, 3}; char *ptr = myarray; Postfix increment has higher association precedence than dereference operator. But the increment does not occur until the next line char c1 = *ptr++; char c2 = *ptr; char c3 = myarray[0]; char c4 = myarray[1]; c1 is 1 c2 is 2 c3 is 1 c4 is 2 http://class.ece.iastate.edu/cpre288 39

Question 6b What are the values of c1, c2, c3, and c4 after the following code executes? char myarray[3] = {1, 2, 3}; char *ptr = myarray; char c1 = (*ptr)++; char c2 = *ptr; char c3 = myarray[0]; char c4 = myarray[1]; http://class.ece.iastate.edu/cpre288 40

Question 6b (answer) char myarray[3] = {1, 2, 3}; char *ptr = myarray; char c1 = (*ptr)++; char c2 = *ptr; char c3 = myarray[0]; char c4 = myarray[1]; c1 is 1 c2 is 2 c3 is 2 c4 is 2 http://class.ece.iastate.edu/cpre288 41

Review Homework Problems and Answers http://class.ece.iastate.edu/cpre288 42