Bitwise Operators Pointers Functions Structs Interrupts (in C)

Slides:



Advertisements
Similar presentations
Question Bank. Explain the syntax of if else statement? Define Union Define global and local variables with example Concept of recursion with example.
Advertisements

7-5 Microoperation An elementary operations performed on data stored in registers or in memory. Transfer Arithmetic Logic: perform bit manipulation on.
Programming and Data Structure
Pointer applications. Arrays and pointers Name of an array is a pointer constant to the first element whose value cannot be changed Address and name refer.
ECE 353: Lab C Pointers and Structs. Basics A pointer holds an address to some variable Notation: – Dereferencing operator: * int *x is a declaration.
True or false A variable of type char can hold the value 301. ( F )
1 Homework Turn in HW2 at start of next class. Starting Chapter 2 K&R. Read ahead. HW3 is on line. –Due: class 9, but a lot to do! –You may want to get.
Program Design and Development
Programming the HC12 in C. Some Key Differences – Note that in C, the starting location of the program is defined when you compile the program, not in.
Logical & shift ops (1) Fall 2007 Lecture 05: Logical Operations.
Chapter 6. 2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single Value Pass by Reference Variable Scope.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Abstract Data Types and Encapsulation Concepts
C Programming for Embedded Systems. fig_06_00 Computer Layers Low-level hardware to high-level software (4GL: “domain-specific”, report-driven, e.g.)
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Pointers (Continuation) 1. Data Pointer A pointer is a programming language data type whose value refers directly to ("points to") another value stored.
Chapter 7 Evaluating the Instruction Set Architecture of H1: Part 1.
A First Book of C++: From Here To There, Third Edition2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single.
C Programming Tutorial – Part I CS Introduction to Operating Systems.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Overloading Binary Operators Two ways to overload –As a member function of a class –As a friend function As member functions –General syntax Data Structures.
Dynamic Memory Allocation The process of allocating memory at run time is known as dynamic memory allocation. C does not Inherently have this facility,
CS212: Object Oriented Analysis and Design Lecture 10: Copy constructor.
8-1 Embedded Systems Fixed-Point Math and Other Optimizations.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Computer Science and Software Engineering University of Wisconsin - Platteville 2. Pointer Yan Shi CS/SE2630 Lecture Notes.
C Programming for Embedded Systems. fig_06_00 Computer Layers Low-level hardware to high-level software (4GL: “domain-specific”, report-driven, e.g.)
CPS120: Introduction to Computer Science Decision Making in Programs.
Fundamentals of C and C++ Programming. EEL 3801 – Lotzi Bölöni Sub-Topics  Basic Program Structure  Variables - Types and Declarations  Basic Program.
Dennis Ritchie 1972 AT & T Bell laboratories (American Telephone and Telegraph) USA 1www.gowreeswar.com.
Pointers: Basics. 2 What is a pointer? First of all, it is a variable, just like other variables you studied  So it has type, storage etc. Difference:
CSNB374: Microprocessor Systems Chapter 5: Procedures and Interrupts.
Copyright 2005, The Ohio State University 1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation.
 2007 Pearson Education, Inc. All rights reserved C Structures, Unions, Bit Manipulations and Enumerations.
CS 376b Introduction to Computer Vision 01 / 23 / 2008 Instructor: Michael Eckmann.
Lecture 3 Classes, Structs, Enums Passing by reference and value Arrays.
C++ / G4MICE Course Session 2 Basic C++ types. Control and Looping Functions in C Function/method signatures and scope.
DOCUMENTATION SECTION GLOBAL DECLARATION SECTION
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
Slides created by: Professor Ian G. Harris Hello World #include main() { printf(“Hello, world.\n”); }  #include is a compiler directive to include (concatenate)
Chapter 10: Classes and Data Abstraction. Objectives In this chapter, you will: Learn about classes Learn about private, protected, and public members.
LHO 22 C and the  The Silicon Labs ISE uses the Keil C51 compiler.  The code size is limiter to 2K  C has replaced PL/M (the original Intel high.
Programming Fundamentals. Topics to be covered Today Recursion Inline Functions Scope and Storage Class A simple class Constructor Destructor.
2: Basics Basics Programming C# © 2003 DevelopMentor, Inc. 12/1/2003.
Chapter 10: Classes and Data Abstraction. Classes Object-oriented design (OOD): a problem solving methodology Objects: components of a solution Class:
ECE 103 Engineering Programming Chapter 4 Operators Herbert G. Mayer, PSU CS Status 6/19/2015 Initial content copied verbatim from ECE 103 material developed.
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
1Object-Oriented Program Development Using C++ Built-in Data Types Data type –Range of values –Set of operations on those values Literal: refers to acceptable.
Pointers: Basics. 2 Address vs. Value Each memory cell has an address associated with it
Chapter 12 Classes and Abstraction
The Machine Model Memory
Format of Assembly language
Java Primer 1: Types, Classes and Operators
C Programming Tutorial – Part I
Pointers.
C Short Overview Lembit Jürimägi.
Student Book An Introduction
C Basics.
C Structures, Unions, Bit Manipulations and Enumerations
Built-In (a.k.a. Native) Types in C++
Coding Concepts (Sub- Programs)
Dr. Bhargavi Dept of CS CHRIST
Interrupt handling Explain how interrupts are used to obtain processor time and how processing of interrupted jobs may later be resumed, (typical.
In this class, we will cover:
Chapter 9: Pointers and String
Functions Reasons Concepts Passing arguments to a function
Computer Architecture Assembly Language
Presentation transcript:

Bitwise Operators Pointers Functions Structs Interrupts (in C)

table_07_00 Bitwise operators: useful for dealing with signals of different widths; NOTE: these are LOGICAL operators and variables are declared UNSIGNED— why? (example: homework 1, problem 1) Additional useful reference:

fig_07_00 Examples of c operations at the byte level

fig_07_01 Example of c program—”portShadow” mirrors what is on port; Note use of parentheses to guarantee order of bitlevel operations (even if we are using default order)

fig_07_02 Using shift operators (remember these are logical):

fig_07_03 Redoing the previous problem with shifts:

fig_07_04 Getting data from the port:

fig_07_05 Using bitlevel operations for arithmetic; Are there any problems with this approach? C: on signed data, left shift undefined if overflow occurs, right shift is implementation-dependent; Java: all integers are signed

fig_07_06 Can use shifts for slightly more complex multiplies and divides; More complex operations (e.g., with 3 1’s in multiplier or divider) are probably not efficient

fig_07_07 Pointers: example data

fig_07_09 Example instruction:

fig_07_10 Example 2 of Instruction execution

fig_07_11 Example: what is output?

fig_07_12a Pointer arithmetic—not for beginners!

fig_07_12b Pointer arithmetic: additional examples

fig_07_13 Constant pointers:

fig_07_14 Using constants and constant pointers:

fig_07_14 Note: pointers can be “generic” or NULL: Generic: Type void: pointer can point to a variable of any type example: 7.3, p. 265 NULL: Pointer needs to be assigned a valid address before dereferencing, otherwise hard-to-find bugs can occur Address 0 is not acceptable Solution: use null pointer address, (void*) 0

fig_07_15 C functions:

fig_07_16 Example:

fig_07_17 Function call: note order of parameters on stack

fig_07_18 Using stack to return result: Function body in memory:

fig_07_20 Pass by value (default in c):

fig_07_21 Pass by reference:

fig_07_22 Information hiding: static qualifier prevents visibility outside this file (even to linker):

fig_07_23 Function documentation: template for header

fig_07_24 We can also define pointers to functions: Dereferencing methods:

fig_07_26 Example:

fig_07_27 Example 2:

fig_07_28 Pointing to add:

fig_07_29 Pointing to subtract: pointer does not know functionality, only address

fig_07_31 User-defined data structure: struct

fig_07_30 User-defined data structure: struct Example:

fig_07_34 Can also define a type and use it repeatedly:

fig_07_35 Syntax for using struct:

fig_07_36 Example: define a rectangle

fig_07_37 One struct using another:

fig_07_38 C code for this example:

fig_07_39 Definign the rectangle type:

fig_07_40 Using point and rectangle definitions:

fig_07_41 Rectangle functions:

fig_07_42 Example program:

fig_07_43 Example: passing a struct to a function:

fig_07_44 Interrupt service routines: ISR—needs to be SHORT and SIMPLE

fig_07_45 How an interrupt occurs: Interrupt may be disabled under certain conditions

fig_07_46 Enable / disable control mechanisms: Global Masking method 1: use priorities method 2: use mask register (bitwise masks) Note: interrupts are transient, if we choose to ignore one we may not be able to service it later