0% found this document useful (0 votes)
9 views90 pages

Year & Sem.: Iii Yr / Vi Sem Faculty Name: A.Manjunathan Department: Ece Unit No.: Iii Title: Program Design and Analysis

The document outlines the concepts of program design and analysis, focusing on assembly language, C code, and control/data flow graphs (CDFG). It discusses the compilation process, including assembly, linking, and optimization techniques, as well as the importance of program validation and testing methods. The document also covers various types of testing, such as black box and clear box testing, emphasizing the need for comprehensive testing in complex systems.

Uploaded by

sriranganvel2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views90 pages

Year & Sem.: Iii Yr / Vi Sem Faculty Name: A.Manjunathan Department: Ece Unit No.: Iii Title: Program Design and Analysis

The document outlines the concepts of program design and analysis, focusing on assembly language, C code, and control/data flow graphs (CDFG). It discusses the compilation process, including assembly, linking, and optimization techniques, as well as the importance of program validation and testing methods. The document also covers various types of testing, such as black box and clear box testing, emphasizing the need for comprehensive testing in complex systems.

Uploaded by

sriranganvel2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 90

K.

RAMAKRISHNAN COLLEGE OF TECHNOLOGY


Samayapuram, Tiruchirappalli – 621 112.

20EC6401 / EMBEDDED AND REAL TIME SYSTEMS

Year & Sem. : III YR / VI SEM


Faculty Name : A.Manjunathan
Department : ECE
Unit No. : III
Title : Program Design and Analysis

1
UNIT III Program Design and Analysis 9

Program design – Model of programs – Assembly and


Linking – Basic compilation techniques – Program
Optimization- Analysis and optimization of execution time,
power, energy, program size – Program validation and
testing.
Model of programs
➢Programs are collection of instructions to
execute a specific task.
➢Models of programs generally called as source
codes.
➢Source codes can not use directly
➢Different types of source codes are
(i) Assembly language
(ii) C code
Model of programs
Assembly language:
▪ Programming languages are C, C++, Java,
Python
▪ But those languages hide the actual working
▪ It is a language that really lies on basic concepts
behind the programming or interaction
between computer hardware.
Model of programs
Assembly language:
✓ It is a low-level language
✓ It will help to communicate directly with computer
hardware.
✓ It uses mnemonics (machine instructions) to
represent the operations that a processor has to do.
✓ It uses hexadecimal and binary values
✓ it is readable by humans.
Model of programs
How Assembly Language Works?
✓ It contain mnemonic codes that specify what the
processor should do.
✓ The mnemonic code that was written by the
programmer was converted into machine language
(binary language) for execution.
✓ An assembler is used to convert assembly code into
machine language.
✓ That machine code is stored in an executable file.
Model of programs
Components of Assembly Language:
❖Registers
❖Commands
❖Instructions
❖Labels
❖Mnemonic
❖Operands & Opcode
Model of programs
C code:
▪ C is a general-purpose (procedural, and middle-level)
programming language.
▪ It allows low-level access to a computer's memory.
▪ It's used for developing computer software, system
programming, applications, games.
▪ C is an excellent choice for beginners → provides a
strong foundation in programming concepts.
▪ It is a platform-independent → code can be compiled
and run on different systems.
Model of programs
➢Must use single mode → because we analyze the
model more easily
➢The fundamental model for program is the
Control/Data flow graph(CDFG)
➢CDFG has construct both data operations
(arithmetic & other computations) and control
operations (conditional)
➢CDFG is clear format → must understand the data
descriptions.
Model of programs

Def. of Data flow graph:


✓A data flow diagram (DFD) is a graphical or
visual representation that uses a standardized set
of symbols and notations to describe a business's
operations through data movement.
✓Each module is an independent object
communicating with others through communication
links
Model of programs
Data flow graph:
▪ DFG is a model of program with no conditional.
▪ In high level program language, a code segment
with no conditionals.
▪ It has only one entry point and exit point is
known as basic block.
▪ ‘C’ code is executed, basic block enters at the
beginning and executes all the statements.
Model of programs
Data flow graph:
A Basic block in ‘C’
✓W = a+b
✓X = a-c
✓Y = x+d
✓X = a+c
✓Z = y+e
Model of programs
Data flow graph:
Model of programs
Types of nodes in Data flow graph:
i) Round nodes – represent operators (0)
ii) Square nodes - represent values ( )
Advantages:
➢ Order of execution operation in mention
➢ Reduced pipeline process
➢ Used to determine feasible reordering of operations
→ capturing data (audio, video, sensor readings)
Model of programs
CONTROL/DATA FLOW GRAPH:

➢Uses a data flow graphs for constructing


decision control
➢Decision control nodes are
i) Decision nodes – used to describe the control in
a sequential program
ii) Data flow nodes – nodes encapsulates a
complete DFG to represent a basic block
Model of programs
CONTROL/DATA FLOW GRAPH:
▪ C++ is defined as the wrapping up of data and
information in a single unit.
▪ In OOPS, Encapsulation is defined as binding
together the data and the functions that
manipulate them.
Two Important property of Encapsulation:
i. Data Protection
ii. Information Hiding
Model of programs
Model of programs
CDFG construction nodes:
i) Rectangular nodes – used to represent the basic
blocks (C codes represent by function call)

ii) Diamond shaped nodes – used to represent the


conditionals
Model of programs
CDFG construction nodes:
Model of programs
CDFG construction nodes:
➢ It specify only a partial ordering on the data flow
computations.
➢ Only one program counter in our execution model
of CDFG
➢ But operations are not executed in parallel
➢ Assembly language program supporting ARM and
VLIW processors (Very Long Instruction Word)
Model of programs
VLIW processors (Very Long Instruction Word):
▪ It is a high-performance processor

▪ It uses instruction level parallelism

▪ It has programs to control the parallel execution of the


instructions.

▪ VLIW Architecture deals with compiler process

▪ It has 10-stage pipeline processor


Assembly and Linking

• Last step in compilation process → assembly and


linking
• But convert list of instructions into an image of
program bits in memory
• Loading → puts in program memory → can be
executed
Assembly and Linking
Assembly and Linking
Types of address:
i) Absolute address
▪ Starting address of the assembly language program
specified by the programmer
ii) Relative address
▪ Origin of the assembly language
▪ Basic function → convert high level language into
executable code
Assembler
✓It is a software tool
✓Convert assembly code into object code
✓It translates assembly language code, a low-level
programming language into machine code
instructions.
✓It acts as a translator between human-readable
assembly instructions and the binary code the
processor understands.
✓Ex: LDA #3 → Assembly code
Assembler
▪ It translate labels into address
▪ It can also translate the opcodes & format the bits in
each instruction.
▪ Local translation is more complex task
▪ The assembler takes care of instruction formats.
Ex: MASM → Microsoft Macro Assembler
TASM → Turbo Assembler
Assembler
Label processing requires making two passes
▪ 1st pass → scanning the code to determine the address of
each label
▪ 2nd pass → assembles the instructions using label values
• In the 1st pass the name of each symbol and its address is
stored in a symbol table
• Symbol table → scanning the instructions first to last
• Scanning the instructions are stored in PLC (Program
Location Counter)
Basic Assembler functions
1.Convert mnemonic operations code to their
equivalent machine language (LDA #3)
2.Convert symbolic operands to their equivalent
machine address (STA TABLE)
3.Build machine instruction in the proper format
(format 1, 2, 3, 4)
4.Convert the data constant to internal machine
representation
5.Write the object program and assembly listing
Assembler derivatives
START → Specify name and starting address for the
program
END → Indicate the end of the source
BYTE → Generate character or hexadecimal constant
WORD → generate one-word integer constant (one
word – 3 bytes)
RESB → Reserves the indicated number of bytes
RESW → Reserves the indicated number of words
Assembler data structures
• 3 major internal data structures

– OPTAB (Operation table)

– SYMTAB (Symbol table)

– LOCCTR (Location Counter)


Assembler
Location Counter (LOCCTR):
• Program counter → processor that contains the
address of the next instruction to be executed from
memory.
• It is a counter used by assemblers to assign memory
locations to labels during the assembly process.
• It keeps track of the current memory location
• It is used to be a variable and help in the assignment
of addresses
• Beginning address specified in the START statement
Assembler
Operation table (OPTAB):
✓It is used to mnemonic operation code convert to
machine language code.
✓It contains information about instruction format
& length.
✓1st pass → validate operation codes in the source
program
✓2nd pass → it is used to translate the operational
codes to machine language.
Assembler
Symbol table (SYMTAB):
➢It is used to store values assigned to labels
➢It is used to track all variables, functions, and
identifiers in a program.
➢It stores information such as the name, type, scope,
and memory location of each identifier.
➢During the early stage of compilation → the
symbol table supports error checking
Linker
• Many assembly language programs are written as
several small pieces
• Breaking a large program into smaller files
• If the program uses library routines (pre
assembled)
• It allows a program to be stitched into out of
several small pieces
• Operates on the objects file
Linker
• Some labels will be used both defined and used in
the same file
• Other labels will be defined in a single file
• Label defined place is known as an entry point
• Label used place is known as an external
references
• Main job of the loader is to resolve external
references
Linker

Phases of linker:

i) 1st phase → it determine the address of the start


of the each object file

ii)2nd phase → loader merges all the symbol tables


Linker

Object Code Design:


▪ Interrupt and I/O devices must be placed in specific
location
▪ Memory management tables must be setup
▪ Global variables used for communication between
processes must be put in location
Linker

Object Code Design:


✓ It is stored in a binary file format, which is specific to
the target architecture and operating system.
✓ The object code file contains both the executable
code and data, as well as information about the
program’s symbols and their memory locations.
✓ It can be linked with other object files to produce a
complete executable program
Linker

Object Code Design:


Linker
Re-entrancy:
(Computing → interrupt middle of execution safely called
again)
• It refers to a function or method that can be safely
interrupted and called again before the previous call is
complete.
• Many programs should be re-entrant.
• A program is re-entrant it can be interrupted by another call
to the function without changing the results of either call.
Linker

Re-location:
▪ Program is reloadable
▪ Object code includes information about the
addresses of symbols in the code,
▪ Linker to adjust the addresses when the code is
linked with other code.
▪ It provides some support from hardware and address
calculation
▪ It is possible to write non-locatable code
Compilation Techniques

▪ It combines translation and optimization


▪ High level language program is translated into
lower level form of instructions
▪ Optimizations try to generate better instruction
sequences
▪ Using Brute Force techniques (trial-and-error
approach) → independently translating source
codes
Compilation Process
➢ Embedded computing system requires controlling the
instruction sequence used to handle the interrupts,
placement of data & instructions in memory.
➢ It is useful to understand how high level language
program is translated instructions.
Compilation = Translation + Optimization
• Translate → High level language program is translated
into lower level form of instructions
• Optimization → try to generate better instruction
sequences
Compilation Process

▪ In this process begins with high level language


code such as C, C++
▪ The high-level language program is parsed to
break it into statements and expressions
▪ In addition, a symbol table is generated, which
includes all the named objects in the program.
Compilation Process
Compilation Process
✓Compiler performs two kinds of optimizations:
i) Instruction-level optimizations → It improves
the performance of a computer program by
executing multiple operations in a single cycle.
(executing operations simultaneously)
ii) Machine-independent optimizations → It is a
software application that can run on various types
of computers without requiring significant
modifications
Basic Compilation Methods

i) Statement translation
ii) Procedures
iii) Data Structures
iv) Compiler optimizations
Basic Compilation Methods

Statement translation:
➢ The basic job of translating the high-level language
program with little or no optimization.
➢ A large amount of the code in a typical application consists
of arithmetic and logical expressions
➢ Understanding how to compile a single expression.
Consider this arithmetic expression:
x = a*b + 5*(c − d)
Basic Compilation Methods
Statement translation
Basic Compilation Methods
Statement translation
➢ In this expression is written in terms of program
variables.
➢ Able to perform memory-to-memory arithmetic directly
on the locations.
➢ In many machines, such as the ARM, we must first load
the variables into registers.
➢ Final result values named as w, x, y, z
➢ It have large programs with multiple expressions – must
allocate registers carefully
Basic Compilation Methods
Procedures:
▪ Two typeIt is major problem in code generation
▪ It is straight forward
▪ Must handle the procedure call and return
▪ Modern programing language is not sufficient to directly
support procedures
Types of procedure:
1. Procedure Linkage
2. Procedure Stack
Basic Compilation Methods
Procedure Linkage:
▪ It provides a way for the program to pass parameters
▪ Provides helps in restoring the values of registers
▪ All procedures in programming language use some
linkage mechanism.

Procedure Stack:
▪ Stack pointer - It defines the end of the current frame
▪ Frame pointer - It defines the end of the last frame
▪ Example – ARM Procedure Call Standard
Basic Compilation Methods

Data Structures:
➢Way of organizing data
➢Must also translate references to data structures
into references to raw materials.
➢Converting data structures requires address
computations – compile time & run time
Basic Compilation Methods
Data Structures:
i) Linked list → fundamental data structure in computer
science, insertion and deletion operations
ii) Array → collection of data organized into rows and
columns
iii) Queue → sequence of task
iv) Structure → to plan or organize
Basic Compilation Methods
Compiler optimizations:
i) Loop Transformations:
• Important programing structure
• It describes in source code
• Large fraction of computation time (to perform a specific
task)
ii) Loop Unrolling:
• Simple and useful transformation
• It helps to expose parallelism (stages of compiler)
Basic Compilation Methods
Compiler optimizations:
iii) Loop fusion:
• Combines two or more loops into a single loop
• Loop must iterate over the same values
• Loop bodies must not have dependency
iv) Loop distribution:
• It is opposite to loop fusion (combines multiple loops into
a single loop)
Program Validation and Testing

➢Complex systems need testing to ensure that


they work as they are intended.
➢It specialized hardware and real time
responsiveness
➢It makes programing more challenging
➢Any available techniques for software testing
Program Validation and Testing

➢It can help to generate a comprehensive set of


tests to ensure that our system works properly.
➢Breaking the testing problem into sub problems
and analyzing each program
➢Each sub program must identify and tested.
➢It provide reasonable amount of testing.
Types of Testing
i) Black box testing:
✓ It doesn’t look at source code
✓ It generate test without looking at the internal
structure of the program
ii) Clear box testing:
✓ looks at source code
✓ Generate test and based on the programing
structure
Clear box testing

➢Examine the source code to determine whether it


works
➢Control/DFG is an important tool
➢To adequately test the program, both control
and data operations are must be exercised.
➢In order to execute and evaluate these tests, it
must be able to control variables in the
program.
Clear box testing

3 – important test:
a) Provide the program with input (i/p is exercise
and its iterated)
b) Execute the program to perform the test
c) Examine the output to determine (whether the
test was successful)
Clear box testing
i) Execution path:
➢It’s a fundamental concept – path of execution
through a program
➢It exercises both the control and data aspects of
the program
➢To execute every complete path
➢Select small number of paths should be able to
cover most practical programs.
Clear box testing
ii) Graph theory:
Graph theory – quantitative handle on the different paths required
Incidence matrix – Contains each rows and columns represent a
node, if a 1 is entered for each node pair connected by an edge.
Basic set – used to measure the control complexity of a program

M = e − n + 2p
• e – number of edges in the flow graph
• n - number of nodes in the flow graph
• p - number of components in the flow graph
Clear box testing
ii) Graph theory:
Clear box testing
iii) Testing strategy:
a) Branch testing - It requires true & false branches of
conditional, Every simple condition is tested expression
atleast once.
b)Domain testing – testing on each side of the boundary, 3
test points are available.
• Ist two point – boundary of the valid region
• 3rd point – outside of the region
Clear box testing

iii) Testing procedure:

i) Controllability – provides program with inputs

ii) Observability – examine the outputs


Black box testing

➢Tests are generated without knowledge of the


code being tested
• Performing two ways:

i) Black box test alone

ii) Black box testing with clear box testing


Black box testing

▪ It has a low probability of finding all the bugs


in a program

▪ It provides a well-rounded test sets

▪ To take tests directly from the specification


for the code under design
Black box testing

1) Random test:
▪ It is a one category of black box testing

▪ Random values are generated with a given


distribution

▪ Expected values are computed independently


of the system
Black box testing
2) Regression test:
✓ It is a software testing
✓ Used to determine whether new problems are raised
the result of software changes
✓ Extremely important category of test
✓ Apply to the latest versions of the system
✓ Simplify the exercise code for the current version of
the code to find different bugs.
Program level performance analysis
▪ Need to understand performance in details
▪ Embedded system must perform functions in
real time.
▪ How programs runs fast
▪ The techniques which are used to analyze
program execution time, properties & power
consumption.
Program level performance analysis
▪ Program performance not equal to CPU performance
▪ CPU performance is more important to understanding
performance of any systems
▪ CPU clock rate is a very unreliable metric for program
performance
▪ Execution time of a program varies with input data
values
▪ Select different execution paths in program
▪ Must analyze the entire program
Measuring Execution speed
• Three methods of Measuring Execution speed

i) Simulator
ii) Timer
iii)Logic analyzer
Measuring Execution speed
i) Simulator:
✓Simulates the execution of that program
✓Its slower that executing program
✓CPU state is visible

ii) Timer (accuracy):


✓ It can be used to measure performance of executing
sections of code
✓ Length of the program measured by accuracy
✓ Code → reset & start
Measuring Execution speed
iii) Logic Analyzer:
➢ It is a measurement device
➢ It is an electronic measuring device that records and
displays the time course of several digital signals.
➢ It is an excellent tool for checking and debugging
digital circuits.
➢ Debugging digital protocols like I2C, UART,
Ethernet, USB
Types of performance measures
(i) Average case Execution time:
✓used in application programming
✓expect for typical data (i/p)
(ii) Worst-case Execution time
✓component in deadline satisfaction
✓It can be spent on any i/p sequence is clearly
✓It must meet deadlines
(iii) Best case Execution time
✓The shortest possible time it takes for a program to run
Elements of program performance
Execution time = Program path + Instruction
timing

✓Solving the problems independently

✓Easy to separate on simpler CPU

✓Instructions traced by the program path


Elements of program performance
Program path:

✓Sequence of instructions executed by the program

✓It is high level language representation of the


program

✓It can be traced high level language specification

✓It is hards to estimate of execution time


(accurate)
Elements of program performance
Instruction timing:
▪ It is based on the sequence of instructions traced by the
program path.
▪ Its take into account data type, pipeline behavior, cache.
Reasons:
1. Not all instructions take the same amount of time
2. Execution times of instructions are not independent
3. It depends on operand values
Software performance optimization

• It is the process of improving the speed,


responsiveness, and functionality of an
application.
(i) Loop optimization

(ii) Code optimization

(iii) Performance optimization strategies


Software performance optimization
Loop optimization:
▪ It is the process of increasing execution speed
and reducing the overheads associated with
loops.

▪ It plays an important role in improving cache


performance and making effective use of parallel
processing.
Software performance optimization
Loop optimization:
▪ Loops are important targets for optimization
(i) Code motion → move unnecessary codes out for
a loop
(ii) Induction variable elimination → loop iteration
process
(iii) Strength reduction → reduce the cost of loop
iteration
Software performance optimization
Code optimization:
✓It aims to enhance code by reducing resource
consumption.
✓High-level generic programming structures are
substituted with low-level programming codes.
✓A nested loop has one or more loops within the
body of another loop.
✓No conditional in nest-loop
✓Use large quantitative of data
Software performance optimization
Performance optimization strategies:

▪ Try to use registers effectively

▪ minimizing latency delays

▪ Make use of page mode (access in the memory


system)
Energy & Power optimization
• Energy → ability to do work (battery
powered systems)

• Power → Energy per unit time

• Measuring energy consumption →


Execute a small loop & measure the current
Energy & Power optimization
➢It is the process of reducing energy
consumption and increasing efficiency while
maintaining performance.

➢It can involve using advanced technologies,


strategic planning, and operational
adjustments.

➢Energy optimization is the process of


maximizing energy efficiency.
Energy & Power optimization
➢Cache behavior is important

➢If cache is too small → program thrashes,


burning energy on external memory access

➢If cache is too large → burns too much


power
Optimizations for Energy
➢1st order optimization → high performance (low
energy)
➢Use registers efficiently
➢Identify and eliminate cache conflicts
➢Cache conflicts → multiple data items in a
memory system compete for the same cache
location
➢Eliminate pipeline process
Efficient loop
Rules:
✓Don’t use function call

✓Keep loop body small to enable local repeat


(only forward branches)

✓Use unsigned integer for loop counter

✓Make use of compiler

You might also like