Program Design and Analysis Chapter 5

Slides:



Advertisements
Similar presentations
Programs in Memory Bryce Boe 2012/08/29 CS32, Summer 2012 B.
Advertisements

MIPS ISA-II: Procedure Calls & Program Assembly. (2) Module Outline Review ISA and understand instruction encodings Arithmetic and Logical Instructions.
MIPS ISA-II: Procedure Calls & Program Assembly. (2) Module Outline Review ISA and understand instruction encodings Arithmetic and Logical Instructions.
1 Lecture 4: Procedure Calls Today’s topics:  Procedure calls  Large constants  The compilation process Reminder: Assignment 1 is due on Thursday.
1 Today’s lecture  Last lecture we started talking about control flow in MIPS (branches)  Finish up control-flow (branches) in MIPS —if/then —loops —case/switch.
Wannabe Lecturer Alexandre Joly inst.eecs.berkeley.edu/~cs61c-te
Lecture 8: MIPS Instruction Set
Chapter 3 Loaders and Linkers
Mr. D. J. Patel, AITS, Rajkot 1 Operating Systems, by Dhananjay Dhamdhere1 Static and Dynamic Memory Allocation Memory allocation is an aspect of a more.
1 Starting a Program The 4 stages that take a C++ program (or any high-level programming language) and execute it in internal memory are: Compiler - C++
Assembly Process. Machine Code Generation Assembling a program entails translating the assembly language into binary machine code This requires more than.
 Procedures (subroutines) allow the programmer to structure programs making them : › easier to understand and debug and › allowing code to be reused.
An introduction to systems programming
Embedded Computer Systems Chapter5: Program design and analysis Eng. Husam Y. Alzaq Islamic University of Gaza 1 © 2010 Husam Alzaq Computers as Components.
MEMORY MANAGEMENT By KUNAL KADAKIA RISHIT SHAH. Memory Memory is a large array of words or bytes, each with its own address. It is a repository of quickly.
OBJECT MODULE FORMATS. The object module format we have employed as an educational device is called OMF (relocatable object format). It’s one of the earliest.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
MIPS coding. SPIM Some links can be found such as:
© 2008 Wayne Wolf Overheads for Computers as Components 2nd ed. Program design and analysis Software components. Representations of programs. Assembly.
CIS250 OPERATING SYSTEMS Memory Management Since we share memory, we need to manage it Memory manager only sees the address A program counter value indicates.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
Topic 2d High-Level languages and Systems Software
1 CS/COE0447 Computer Organization & Assembly Language Chapter 2 Part 4.
5-1 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Principles.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /29/2013 Lecture 13: Compile-Link-Load Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE.
Introduction to Compilers. Related Area Programming languages Machine architecture Language theory Algorithms Data structures Operating systems Software.
CS412/413 Introduction to Compilers and Translators April 14, 1999 Lecture 29: Linking and loading.
© 2000 Morgan Kaufman Overheads for Computers as Components Program design and analysis zDesign patterns zRepresentations of programs zAssembly and linking.
LINKERS Execution of a program written in a language L involves the following steps: 1.Translation of the program: Performed by the translator for language.
The Assembly Process Computer Organization and Assembly Language: Module 10.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
Hello world !!! ASCII representation of hello.c.
Operating Systems A Biswas, Dept. of Information Technology.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Binding & Dynamic Linking Presented by: Raunak Sulekh(1013) Pooja Kapoor(1008)
Lecture 3 Translation.
Advanced Computer Systems
Computer Architecture & Operations I
Chapter 2 Memory and process management
Lecture 6: Assembly Programs
Computer Science 210 Computer Organization
MIPS Instruction Set Advantages
Compiler Construction (CS-636)
System Programming and administration
Linking & Loading.
Chapter 9 – Real Memory Organization and Management
Chapter 8 Main Memory.
Topic 2e High-Level languages and Systems Software
Computer Science 210 Computer Organization
Chapter 7 LC-2 Assembly Language.
Instructions - Type and Format
Memory Management 11/17/2018 A. Berrached:CS4315:UHD.
Code Generation.
Memory Management Tasks
Lecture Topics: 11/1 General Operating System Concepts Processes
Computer Organization and Design Assembly & Compilation
Linking & Loading CS-502 Operating Systems
A Simple Two-Pass Assembler
Computer Architecture
System Programming by Leland L. Beck Chapter 2
Lecture 6: Assembly Programs
Introduction to Data Structure
Introduction to Computer Systems
Program Design and Analysis Chapter 5
10/6: Lecture Topics C Brainteaser More on Procedure Call
Linking & Loading CS-502 Operating Systems
An introduction to systems programming
Program Assembly.
COMP755 Advanced Operating Systems
Presentation transcript:

Program Design and Analysis Chapter 5 COE 306: Introduction to Embedded Systems Dr. Aiman El-Maleh Computer Engineering Department College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals

Next . . . Embedded Software Components Models of Programs State Machines Circular Buffers Queues Models of Programs The Compilation Process

Embedded Software Components Embedded code must run at a required rate to meet system deadlines, fit into the allowed amount of memory, meet power consumption requirements Some of the most common software components in embedded systems are: 1. State machines: well suited to reactive systems such as user interfaces 2. Circular buffers: useful in digital signal processing 3. Queues: useful in digital signal processing

Software State Machine State machine keeps internal state as a variable, changes state based on inputs Uses: control-dominated code; reactive systems Example: Seat Belt Controller Turn on buzzer if a person sits in a seat and does not fasten the seat belt within a fixed amount of time Inputs: Seat sensor: to know when a person has sat down Seat belt sensor: to know when the belt is fastened Timer: to know when the fixed interval has elapsed Output: the buzzer States: Idle, seated, buzzer, belted

State Machine Example: Seat Belt Controller

Seat Belt Controller: C Code #define IDLE 0 #define BELTED 2 #define SEATED 1 #define BUZZER 3 buzzer_on = OFF; timer_on = OFF; switch(state) { case IDLE: if (seat) { state = SEATED; timer_on = TRUE; } break; case SEATED: if (belt) state = BELTED; else if (timer) {state = BUZZER; buzzer_on = TRUE; } break; case BELTED: if (!seat) state = IDLE; else if (!belt) { state = SEATED; timer_on = TRUE; } break; case BUZZER: if (belt) {state = BELTED; buzzer_on = OFF;} else if (!seat) { state = IDLE; buzzer_on = OFF; } }

Circular Buffer A data structure that allows efficient stream processing Commonly used in signal processing: new data constantly arrives; each datum has a limited lifetime. Use a circular buffer to hold the data stream x1 x2 x3 x4 x5 x6 Data stream t1 t2 t3 x5 x1 x6 x2 x7 x3 x4 Circular buffer

Circular Buffer: C Implementation Data structure put() init() get() void init() { for (int i = 0; i < SIZE; i++) buffer[i] = 0; pos = SIZE - 1; } #define SIZE 3 int buffer[SIZE]; int pos; void put(int value) { pos = (pos + 1) % SIZE; buffer[pos] = value; } /* get the ith value from the circular buffer; zero being the newest value */ int get(int i) { int index = (pos - i) % SIZE; return buffer[index]; }

Using Circular Buffers: FIR Filter One output: for (i = 0; i < SIZE; i++) y += x[i] * b[i]; Processing as a stream using a circular buffer: int fir(int value) { int i, y; put(value); for (i = 0, y = 0; i < SIZE; i++) y += b[i] * get(i); return y; }

Queues Used when data arrival and departure or amount is unpredictable A queue is also referred to as an elastic buffer Circular buffer has a fixed number of data elements while a queue may have varying number of elements Queues can be implemented based on linked lists or arrays A linked list allows arbitrary sizes but requires dynamic memory allocation

An Array-Based Queue #define SIZE 5 int q[SIZE]; int head, tail; void queue_init() { head = 0; tail = 0; } void enqueue(int value) { if ((tail+1) % SIZE == head) error("The queue is full"); q[tail] = value; tail = (tail+1) % SIZE; } int dequeue() { int value; if (head == tail) error("The queue is empty"); value = q[head]; head = (head+1) % SIZE; return value; }

Producer/Consumer Systems Queues allow varying input and output rates Queues modify the flow of control in the system as well as store data

Models of Programs Source code is not a good representation for programs: clumsy language-dependent Compilers derive intermediate representations to manipulate and optimize the program. Abstraction allows easier analysis One general model describes all language-specific models

Data Flow Graph (DFG) A data flow graph is a model of a program with no conditionals Describes the minimal ordering requirements on operations Single-Assignment Form: A variable appears only once on the left-hand side x = a + b; y = c - d; z = x * y; y = b + d; original basic block x = a + b; y = c - d; z = x * y; y1 = b + d; single assignment form

Data Flow Graph (DFG) x = a + b; y = c - d; z = x * y; y1 = b + d; single assignment form The data flow graph determines feasible reorderings of operations, which may help reduce pipeline or cache conflicts

Control-Data Flow Graph (CDFG) CDFG: represents control and data. Uses data flow graphs as components. A CDFG has two types of nodes: Data flow nodes: encapsulates a complete data flow graph Write operations in basic block form for simplicity Decision nodes: describe all types of control (branch)

CDFG Example if (cond1) bb1(); else bb2(); bb3(); switch (test1) { case c1: bb4(); break; case c2: bb5(); break; case c3: bb6(); break; }

CDFG: For Loop For Loop: for (i=0; i<N; i++) loop_body(); Equivalent While Loop: i=0; while (i<N) { loop_body(); i++; }

Compilation and Execution an image of the program’s bits in memory

From Assembly Code to Execution Human-readable Abstracts out instruction format Abstracts out exact addresses The Assembler Translates assembly code to binary representation (object code) according to instruction formats Partially translates labels into addresses The Linker Determines all addresses across multiple program files Generates the executable binary file

The Assembler Labels are the most important abstraction provided by the assembler Label processing requires two passes: 1. Determine label addresses By advancing a Program Location Counter (PLC) PLC is incremented by instruction size (4 bytes in ARM) 2. Assemble instructions using computed label values The ORG pseudo-op specifies the origin, i.e. first address, of the program Relocatable code requires alternative mechanisms both in assembly code and generated object code

The Symbol Table Label addresses, resulting from the first pass, are recorded in a symbol table A pseudo-op allows adding symbols to the table without occupying space in program memory: EQU—does not advance PLC Example:

Object File Header location of main entry point (if any) size and position of pieces of file Text Segment: instructions Data Segment static data (local/global vars, strings, constants) Relocation Information Instructions and data that depend on actual addresses Linker patches these bits after relocating segments Symbol Table External (exported) references Unresolved (imported) references

Object File Formats Unix Windows a.out COFF: Common Object File Format ELF: Executable and Linking Format … Windows PE: Portable Executable All support both executable and object files

Linking Combines several object modules into a single executable module Allows programs to be divided into multiple files Allows using pre-assembled libraries Puts modules in order Modifies object code to make the necessary links between files Relocate each object’s text and data segments Resolve as-yet-unresolved symbols Record top-level entry point in executable file

The Linker The linker proceeds in two phases: 1. Determine the first address in each object file, based on: The order in which the files are to be loaded The size of each object file 2. Merge symbol tables, and update relative addresses in object files The assembler must identify label references in object files Both absolute and relative addressing are important in embedded systems: Interrupts and I/O registers require absolute addressing

Example

Example

Example: Objdump Disassembly

Example: Objdump Symbols

calc.exe main.o math.o printf.o math 1 1 2 .text A 2 main Symbol tbl B ... 21032040 0C40023C 1b301402 3C041000 34040004 21035000 1b80050c 8C048004 21047002 0C400020 10201000 21040330 22500102 ... 0C000000 21035000 1b80050C 8C040000 21047002 ... 21032040 0C000000 1b301402 3C040000 34040000 0040 0000 JAL printf 1 LUI 1000 ORI 0004 LA uname 2 1 math .text 0040 0100 20 T square 00 D pi *UND* printf *UND* uname A 2 00 T main 00 D uname *UND* printf *UND* pi B main Symbol tbl LW $4,-32764($gp) $4 = pi 28, JL, printf 30, LUI, uname 34, LA, uname JAL square 0040 0200 40, JL, printf 4C, LW/gp, pi 50, JL, square printf 3 printf.o Relocation info 1000 0000 00000003 0077616B pi 1000 0004 uname ... 3 Entry:0040 0100 text:0040 0000 data:1000 0000 3C T printf

Linking Example