Embedded Computer Systems Chapter5: Program design and analysis Eng. Husam Y. Alzaq Islamic University of Gaza 1 © 2010 Husam Alzaq Computers as Components.

Slides:



Advertisements
Similar presentations
© 2008 Wayne Wolf Overheads for Computers as Components 2 nd ed. Program design and analysis zCompilation flow. zBasic statement translation. zBasic optimizations.
Advertisements

Chapter 10- Instruction set architectures
1 Lecture 4: Procedure Calls Today’s topics:  Procedure calls  Large constants  The compilation process Reminder: Assignment 1 is due on Thursday.
Assembly Code Example Selection Sort.
1 Compiler Construction Intermediate Code Generation.
Lecture 8: MIPS Instruction Set
The Functions and Purposes of Translators Code Generation (Intermediate Code, Optimisation, Final Code), Linkers & Loaders.
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++
System Programming Mr. M. V. Nikum (B.E.I.T). Introduction What is System? System is the collection of various components Ex:- College is a system What.
The assembler is the system program that translate source code written in assembly language to object code( Machine Language) and other information for.
1 Copyright © 2013 Elsevier Inc. All rights reserved. Chapter 5 Program Design and Analysis.
ADT Stacks and Queues. Stack: Logical Level “An ordered group of homogeneous items or elements in which items are added and removed from only one end.”
Program Representations. Representing programs Goals.
Chapter 8 Runtime Support. How program structures are implemented in a computer memory? The evolution of programming language design has led to the creation.
Lecture 11 – Code Generation Eran Yahav 1 Reference: Dragon 8. MCD
Code Generation Mooly Sagiv html:// Chapter 4.
Representing programs Goals. Representing programs Primary goals –analysis is easy and effective just a few cases to handle directly link related things.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 33: Code Generation and Linking COMP 144 Programming Language Concepts Spring 2002.
Assemblers Dr. Monther Aldwairi 10/21/20071Dr. Monther Aldwairi.
Tentative Schedule 20/12 Interpreter+ Code Generation 27/12 Code Generation for Control Flow 3/1 Activation Records 10/1 Program Analysis 17/1 Register.
Embedded Software Development. Page 2 Hardware and software architectures Hardware and software are intimately related: software doesn’t run without hardware;
The Assembly Language Level
Software Development Process Compiler Linker C File Asm. File Binary File Exec. File Assemble r Library Implementation Phase Debugger Profiler Verification.
Introduction to Code Generation Mooly Sagiv html:// Chapter 4.
Improving code generation. Better code generation requires greater context Over expressions: optimal ordering of subtrees Over basic blocks: Common subexpression.
Topic 1: Introduction to Computers and Programming
CS 101 Problem Solving and Structured Programming in C Sami Rollins Spring 2003.
Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved The Assembly Language Level.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 1 Introduction to Computers and Programming.
CIS Computer Programming Logic
© 2000 Morgan Kaufman Overheads for Computers as Components Instruction sets zComputer architecture taxonomy. zAssembly language. ARM processor  PDA’s,
© 2000 Morgan Kaufman Overheads for Computers as Components Program design and analysis zDesigning embedded programs is more difficult and challenging.
A Simple Two-Pass Assembler
MIPS coding. SPIM Some links can be found such as:
© 2000 Morgan Kaufman Overheads for Computers as Components Program design and analysis zProgram validation and testing.
© 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.
Languages and the Machine Chapter 5 CS221. Topics The Compilation Process The Assembly Process Linking and Loading Macros We will skip –Case Study: Extensions.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
The LC-3 – Chapter 7 COMP 2620 Dr. James Money COMP
Chapter 5 Program Design and Analysis 金仲達教授 清華大學資訊工程學系 (Slides are taken from the textbook slides)
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.
Chapter 1 Introduction. Chapter 1 -- Introduction2  Def: Compiler --  a program that translates a program written in a language like Pascal, C, PL/I,
1 Control Flow Analysis Topic today Representation and Analysis Paper (Sections 1, 2) For next class: Read Representation and Analysis Paper (Section 3)
© 2000 Morgan Kaufman Overheads for Computers as Components Program design and analysis zDesign patterns zRepresentations of programs zAssembly and linking.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
Evolution of C and C++ n C was developed by Dennis Ritchie at Bell Labs (early 1970s) as a systems programming language n C later evolved into a general-purpose.
Hello world !!! ASCII representation of hello.c.
INTRODUCTION TO PROGRAMING System Development Mansoura October 2015.
Operating Systems A Biswas, Dept. of Information Technology.
Software Engineering Algorithms, Compilers, & Lifecycle.
Binding & Dynamic Linking Presented by: Raunak Sulekh(1013) Pooja Kapoor(1008)
Chapter Goals Describe the application development process and the role of methodologies, models, and tools Compare and contrast programming language generations.
EC6703 EMBEDDED AND REAL TIME SYSTEMS
Writing Functions in Assembly
Computer Science 210 Computer Organization
The University of Adelaide, School of Computer Science
Writing Functions in Assembly
Computer Science 210 Computer Organization
The Assembly Language Level
Introduction to System Programming
Chapter 7 LC-2 Assembly Language.
The Assembly Language Level
A Simple Two-Pass Assembler
Program Design and Analysis Chapter 5
Chapter 6 Programming the basic computer
Program Design and Analysis Chapter 5
Presentation transcript:

Embedded Computer Systems Chapter5: Program design and analysis Eng. Husam Y. Alzaq Islamic University of Gaza 1 © 2010 Husam Alzaq Computers as Components

Program design and analysis zSoftware components. zRepresentations of programs. zAssembly and linking. 2 © 2010 Husam Alzaq Computers as Components

Software state machine zState machine keeps internal state as a variable, changes state based on inputs. zUses: ycontrol-dominated code; yreactive systems. 3 © 2010 Husam Alzaq Computers as Components

State machine example idle buzzerseated belted no seat/- seat/timer on no belt and no timer/- no belt/timer on belt/- belt/ buzzer off Belt/buzzer on no seat/- no seat/ buzzer off 4 © 2010 Husam Alzaq Computers as Components

C implementation #define IDLE 0 #define SEATED 1 #define BELTED 2 #define BUZZER 3 switch (state) { case IDLE: if (seat) { state = SEATED; timer_on = TRUE; } break; case SEATED: if (belt) state = BELTED; else if (timer) state = BUZZER; break; … } 5 © 2010 Husam Alzaq Computers as Components

Signal processing and circular buffer zCommonly used in signal processing: ynew data constantly arrives; yeach datum has a limited lifetime. zUse a circular buffer to hold the data stream. d1d2d3d4d5d6d7 time ttime t+1 6 © 2010 Husam Alzaq Computers as Components

Circular buffer x1x2x3x4x5x6 t1t1 t2t2 t3t3 Data stream x1x2x3x4 Circular buffer x5x6x7 7 © 2010 Husam Alzaq Computers as Components

Circular buffers zIndexes locate currently used data, current input data: d1 d2 d3 d4 time t1 use input d5 d2 d3 d4 time t1+1 use input 8 © 2010 Husam Alzaq Computers as Components

Circular buffer implementation: FIR filter int circ_buffer[N], circ_buffer_head = 0; int c[N]; /* coefficients */ … int ibuf, ic; for (f=0, ibuff=circ_buff_head, ic=0; ic<N; ibuff=(ibuff==N-1?0:ibuff++), ic++) f = f + c[ic]*circ_buffer[ibuf]; 9 © 2010 Husam Alzaq Computers as Components

Queues zElastic buffer: holds data that arrives irregularly. 10 © 2010 Husam Alzaq Computers as Components

Buffer-based queues #define Q_SIZE 32 #define Q_MAX (Q_SIZE-1) int q[Q_MAX], head, tail; void initialize_queue() { head = tail = 0; } void enqueue(int val) { if (((tail+1)%Q_SIZE) == head) error(); q[tail]=val; if (tail == Q_MAX) tail = 0; else tail++; } int dequeue() { int returnval; if (head == tail) error(); returnval = q[head]; if (head == Q_MAX) head = 0; else head++; return returnval; } 11 © 2010 Husam Alzaq Computers as Components

Models of programs zSource code is not a good representation for programs: yclumsy; yleaves much information implicit. zCompilers derive intermediate representations to manipulate and optiize the program. 12 © 2010 Husam Alzaq Computers as Components

Data flow graph zDFG: data flow graph. zDoes not represent control. zModels basic block: code with no entry or exit. zDescribes the minimal ordering requirements on operations. 13 © 2010 Husam Alzaq Computers as Components

Single assignment form 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 14 © 2010 Husam Alzaq Computers as Components

Data flow graph x = a + b; y = c - d; z = x * y; y1 = b + d; single assignment form + - +* DFG a bc d z x y y1 15 © 2010 Husam Alzaq Computers as Components

DFGs and partial orders Partial order: z a+b, c-d; b+d and x*y Can do pairs of operations in any order * a bc d z x y y1 16 © 2010 Husam Alzaq Computers as Components

Control-data flow graph zCDFG: represents control and data. zUses data flow graphs as components. zTwo types of nodes: ydecision; ydata flow. 17

© 2010 Husam Alzaq Computers as Components Data flow node Encapsulates a data flow graph: Write operations in basic block form for simplicity. x = a + b; y = c + d 18

© 2010 Husam Alzaq Computers as Components Control cond T F Equivalent forms value v1 v2 v3 v4 19

CDFG example if (cond1) bb1(); else bb2(); bb3(); switch (test1) { case c1: bb4(); break; case c2: bb5(); break; case c3: bb6(); break; } cond1 bb1() bb2() bb3() bb4() test1 bb5()bb6() T F c1 c2 c3 20 © 2010 Husam Alzaq Computers as Components

for loop for (i=0; i<N; i++) loop_body(); for loop i=0; while (i<N) { loop_body(); i++; } equivalent i<N loop_body() T F i=0 21 © 2010 Husam Alzaq Computers as Components

Assembly and linking zLast steps in compilation: HLL compile assembly assemble HLL assembly link executable link 22 © 2010 Husam Alzaq Computers as Components

Multiple-module programs zPrograms may be composed from several files. zAddresses become more specific during processing: yrelative addresses are measured relative to the start of a module; yabsolute addresses are measured relative to the start of the CPU address space. 23 © 2010 Husam Alzaq Computers as Components

Assemblers zMajor tasks: ygenerate binary for symbolic instructions; ytranslate labels into addresses; yhandle pseudo-ops (data, etc.). zGenerally one-to-one translation. zAssembly labels: ORG 100 label1ADR r4,c 24 © 2010 Husam Alzaq Computers as Components

Symbol table ADD r0,r1,r2 xxADD r3,r4,r5 CMP r0,r3 yySUB r5,r6,r7 assembly code xx0x8 yy0x10 symbol table 25 © 2010 Husam Alzaq Computers as Components

Symbol table generation zUse program location counter (PLC) to determine address of each location. zScan program, keeping count of PLC. zAddresses are generated at assembly time, not execution time. 26 © 2010 Husam Alzaq Computers as Components

Symbol table example ADD r0,r1,r2 xxADD r3,r4,r5 CMP r0,r3 yySUB r5,r6,r7 xx0x8 yy0x10 27 © 2010 Husam Alzaq Computers as Components

Two-pass assembly zPass 1: ygenerate symbol table zPass 2: ygenerate binary instructions 28 © 2010 Husam Alzaq Computers as Components

Relative address generation zSome label values may not be known at assembly time. zLabels within the module may be kept in relative form. zMust keep track of external labels---can’t generate full binary for instructions that use external labels. 29 © 2010 Husam Alzaq Computers as Components

Pseudo-operations zPseudo-ops do not generate instructions: yORG sets program location. yEQU generates symbol table entry without advancing PLC. yData statements define data blocks. 30 © 2010 Husam Alzaq Computers as Components

Linking zCombines several object modules into a single executable module. zJobs: yput modules in order; yresolve labels across modules. 31 © 2010 Husam Alzaq Computers as Components

external reference entry point Externals and entry points xxxADD r1,r2,r3 B a yyy%1 aADR r4,yyy ADD r3,r4,r5 32 © 2010 Husam Alzaq Computers as Components

Module ordering zCode modules must be placed in absolute positions in the memory space. zLoad map or linker flags control the order of modules. module1 module2 module3 33 © 2010 Husam Alzaq Computers as Components

Dynamic linking zSome operating systems link modules dynamically at run time: yshares one copy of library among all executing programs; yallows programs to be updated with new versions of libraries. 34 © 2010 Husam Alzaq Computers as Components