SlideShare a Scribd company logo
1 of 32
•••••••••••••••••••••••••••••••••
WHAT IS EMBEDDED C?

Whenever the conventional „C‟
language and its extensions are
used for programming
embedded systems, it is
referred to as “Embedded C”
programming.
C V/S EMBEDDED C

   „C‟ is a well structured,      Embedded „C‟ can be
    well defined and                considered as a subset
    standardised general            of conventional „C‟
    purpose programming             language.
    language.                      A software program
                                    called „Cross compiler‟
   A platform specific             is used for the
    application , known as ,        conversion of programs
    compiler is used for the        written in Embedded
    conversion of programs          „C‟ to target
    written in C to the             processor/controller
    target processor                specific
    specific binary files.          instructions(machine
                                    language).
COMPILER V/S CROSS COMPILER

   Compiler is a               Cross compilers are
    software tool that           software tools used in
                                 cross platform
    converts a source            development applications.
    code written in a high       (In cross platform
    level language on top        development , the
    of a particular              compiler running on a
    operating system             particular target
                                 processor/OS converts the
    running on a specific        source code to machine
    target processor             code for a target
    architecture.                processor whose
                                 architecture and
                                 instruction set is different
                                 from the current
                                 development environment
KEYWORDS

 These are the reserved names used by the
  „C ‟ language.
 All keywords should be written in ‘lowercase’
  letters.
Examples- int, char, double, float, void, while, for,
  long etc.
ANSI „C‟ supports 32 such keywords.
IDENTIFIERS

 Identifiers are user defined names and
  labels.
 Can contain letters of English alphabet(both
  upper and lower case) and numbers.
 Note: The starting character of an identifier
  should be a letter and the only special
  character allowed in identifier is
  underscore(_).
DATATYPES

   Datatype represents the type of data held by
    a variable.
     Datatype              Size(Bits)
     char                  8
     int                   16
     float                 32
     double                64

    Note: The storage size may vary for data type
    depending on the cross compiler in use for
    embedded applications.
STORAGE CLASS

 Keywords   related to storage class provide
  information on the scope i.e. visibility or
  accessibility and lifetime i.e. existence of a
  variable.
 „C‟ supports four types of storage classes .
Storage Class   Meaning                    Comments
auto            Variables declared         Scope and accessibility
                inside a function.         is restricted within the
                Default storage class is   function where the
                auto.                      variable is declared.
                                           No initialization.

register        Variables stored in the    Same as auto in scope
                CPU register of            and access.
                processor.                 The decision on
                Reduces access time of     whether a variable
                variable.                  needs to be kept in
                                           CPU register of the
                                           processor depends on
                                           the compiler.
static          Local variable with        Retains the value
                lifetime same as that      throughout the
                of the program.            program.
                                           By default initialises to
                                           zero on variable
                                           creation.
Storage Class   Meaning                   Comments
static                                    Accessibility depends
                                          on where the
                                          variable is declared.
extern          Variables accessible      Can be modified by
                to all functions in a     any function within a
                file and all files in a   file or across
                multiple file             multiple files.
                program.
ARITHMETIC OPERATIONS

Operator   Operation        Comments
+          Addition         Adds variables or
                            numbers
-          Subtraction      Subtracts variables or
                            numbers
*          Multiplication   Multiplies variables
                            or numbers
/          Division         Divides variables or
                            numbers
%          Remainder        Finds the remainder
                            of a division
LOGICAL OPERATIONS

 Fordecision making and program control
 transfer.
   Operator    Operation     Comments

   &&          Logical AND   Performs logical
                             AND
                             operation.Output
                             is true(logic 1) if
                             both
                             operands(left to
                             right of &&
                             operator) are
                             true.
Operator   Operation     Comments


||         Logical OR    Performs logical OR
                         operation.Output is
                         true(logic 1) if either
                         operand is true.




!          Logical NOT   Performs logical
                         negation.Operand is
                         complemented.
RELATIONAL OPEATIONS

 Fordecision making and program control
 transfer on the basis of comparison.
 Operator      Operation      Comments

 <             Less than      Checks whether the
                              operand on the left
                              side of „<‟ operator
                              is less than the
                              operand on the right
                              side.If yes return
                              logic one, else
                              return logic zero.
Operator   Operations              Comments
>          Greater than            Checks whether the
                                   operand on the left
                                   side of „>‟ operator is
                                   greater than the
                                   operand on the right
                                   side.If yes return
                                   logic one else return
                                   logic zero.
<=         Less than or equal to   Checks whether the
                                   operand on the left
                                   side of „<=‟ operator
                                   is less than or equal
                                   to the operand on
                                   the right side.If yes
                                   return logic one, else
                                   return logic zero.
Operator   Operation             Comments
==         Checks equality       Checks whether the
                                 operand on the left
                                 side of „==‟ operator
                                 is equal to the
                                 operand on the right
                                 side.If yes return
                                 logic one, else return
                                 logic zero.
!=         Checks non-equality   Checks whether the
                                 operand on the left
                                 side of „!=‟ operator
                                 is not equal to the
                                 operand on the right
                                 side.If yes return
                                 logic one, else return
                                 logic zero.
BRANCHING INSTRUCTIONS

 CONDITIONAL           UNCONDITIONAL
  BRANCHING              BRANCHING
 Depends on            These instructions
  certain conditions     divert program
  and if the             execution
  conditions are         unconditionally.
  met, the program
  execution is
  diverted
  accordingly.
Conditional Branching   Explanation
instruction
//if statement          Evaluates the expression first and
                        if it is true executes the
                        statements given within the { }
if(expression){         braces and continue execution of
Statement 1;            statements following the closing
Statement 2;            curly brace(}).Skips the
………………… ;               execution of the statements
}                       within the curly brace{ } if
Statement 3;            expression is false and continue
………………… ;               execution of statements
                        following the closing curly brace
                        (}).

                        One way branching
Conditional Branching   Explanation
Instruction
//if else statement     Evaluates the expression first
if(expression){         and if it is true executes the
if_statement1;          statements given within the { }
if_statement2;          braces following if (expression)
………………….. ;             and continue execution of the
}                       statements following the closing
else                    curly brace (}) of else block.
{                       Executes the statements within
else_statement1;        the curly brace { } following the
else_statement2;        else, if the expression is false
………………………. ;            and continue execution of
}                       statements following the closing
statement 3;            curly brace(}) of else.
Conditional Branching     Explanation
instruction
//switch case statement   Tests the value of a given
                          expression against a list of case
switch(expression){       values for a matching
case value 1:             condition.The expression and
      break;              case values should be
case value 2:             integers.value1, value2, etc. are
      break;              integers.If a match found,
default:                  executes the statement following
      break;              the case and breaks from the
}                         switch.If no match found,
                          executes the default case.

                          Used for multiple branching.
Conditional branching              Explanation
instruction
//conditional operator             Used for assigning a value
//?exp1:exp2                       depending on the
(expression) ?exp1:exp2            (expression).(expression) is
                                   calculated first and if it is
E.g.                               greater than 0, evaluates exp1
if(x>y)                            and returns it as a result of
A=1;                               operation else evaluate exp2 and
else                               returns it as result.
A=0;                               The return value is assigned to
                                   some variable.
Can be written using conditional   It is a combination of if else with
operator as                        assignment statement.

A=(x>y)1:0                         Used for two way branching.
Unconditional Branching   Explanation
instruction
goto                      Goto is used as an unconditional
                          branching instruction.goto
                          transfers the program control
                          indicated by a label following
                          the goto statement.the label
                          inicated by goto statement can
                          be anywhere in the program
                          either before or after the goto
                          label instruction.

                          goto is generally used to come
                          out of deeply nested loops in
                          abnormal conditions or errors.
#include<stdio.h>
void main() {
 int n=0;
 loop: ;
 printf("n%d", n);
    n++;
    if (n<10) {
    goto loop;
    }
    getch();
    return 0;
}
LOOPING INSTRUCTIONS

 For executing a particular block of code
  repeatedly till a condition is met or wait till an
  event is fired.
 Used to check the status of certain I/O ports,
  registers, etc. and also for producing delays.
 Certain devices allow write/read operations to
  and from some registers of the device only when
  the device is ready and the device ready is
  normally indicated by a status register or by
  setting/clearing certain bits of status
  registers.Hence the program should keep on
  reading the status register till the device ready
  indication comes.
Looping instruction   explanation


//while statement     Entry controlled loop statement.
                      The expression is evaluated first
while (expression){   and if it is true the body of the
                      loop is entered and
body of while loop    executed.Execution of „body of
                      while loop‟ is repeated till the
}                     expression becomes false.
//using while loop

char *status_reg=char(*)0x3000 ; /*Declares
  memory mapped register*/

while(*status_reg!=0x01); /*Wait till
 status_reg=0x01 i.e. device ready state*/
Looping instruction   explanation


//do while loop       The „body of the loop‟ is
                      executed at least once.At the
do{                   end of each execution of the
                      „body of the loop‟, the while
body of do loop       condition (expression) is
                      evaluated and if it is true the
}                     loop is repeated, else loop is
while(expression)     terminated.
//using do while loop

char *status_reg=(char*)0x3000;
do{

// body of do loop

}while(*status_reg!=0x01); /* loop till
  status_reg=0x01 */
Looping instruction           explanation

//for loop                    Entry controlled loop.
                              Enters and executes „the body of
for(initialisation;test for   loop‟ only if the test for the
condition;update variable){   condition is true. for loop
                              contains a loop control variable
body of for loop              which may be initialised within
                              the initialisation part of the
}                             loop.
                              Multiple variables can be
                              initialised with „,‟ operator.
// using for loop

char *status_reg=(char*) 0x3000;
for(;(*status_reg!=0x01););
 Introduction   to Embedded Systems by
 Shibu KV

More Related Content

What's hot

Microcontroller presentation
Microcontroller presentationMicrocontroller presentation
Microcontroller presentationxavierpaulino
 
8086 modes
8086 modes8086 modes
8086 modesPDFSHARE
 
Architecture of 8051
Architecture of 8051Architecture of 8051
Architecture of 8051hello_priti
 
8051 Microcontroller ppt
8051 Microcontroller ppt8051 Microcontroller ppt
8051 Microcontroller pptRahul Kumar
 
Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)Dhaval Kaneria
 
Embedded System Tools ppt
Embedded System Tools  pptEmbedded System Tools  ppt
Embedded System Tools pptHalai Hansika
 
I/O port programming in 8051
I/O port programming in 8051I/O port programming in 8051
I/O port programming in 8051ssuser3a47cb
 
8259 Programmable Interrupt Controller
8259 Programmable Interrupt Controller8259 Programmable Interrupt Controller
8259 Programmable Interrupt Controllerabhikalmegh
 
8085 interfacing with memory chips
8085 interfacing with memory chips8085 interfacing with memory chips
8085 interfacing with memory chipsSrikrishna Thota
 
Introduction to Embedded System
Introduction to Embedded SystemIntroduction to Embedded System
Introduction to Embedded SystemZakaria Gomaa
 
8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil Kaware8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil KawareProf. Swapnil V. Kaware
 
Design of embedded systems
Design of embedded systemsDesign of embedded systems
Design of embedded systemsPradeep Kumar TS
 

What's hot (20)

Serial Communication in 8051
Serial Communication in 8051Serial Communication in 8051
Serial Communication in 8051
 
Microcontroller presentation
Microcontroller presentationMicrocontroller presentation
Microcontroller presentation
 
8086 modes
8086 modes8086 modes
8086 modes
 
Embedded system introduction
Embedded system introductionEmbedded system introduction
Embedded system introduction
 
Architecture of 8051
Architecture of 8051Architecture of 8051
Architecture of 8051
 
8051 Microcontroller ppt
8051 Microcontroller ppt8051 Microcontroller ppt
8051 Microcontroller ppt
 
Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)
 
Embedded System Tools ppt
Embedded System Tools  pptEmbedded System Tools  ppt
Embedded System Tools ppt
 
I/O port programming in 8051
I/O port programming in 8051I/O port programming in 8051
I/O port programming in 8051
 
8259 Programmable Interrupt Controller
8259 Programmable Interrupt Controller8259 Programmable Interrupt Controller
8259 Programmable Interrupt Controller
 
ARM Processors
ARM ProcessorsARM Processors
ARM Processors
 
8085 interfacing with memory chips
8085 interfacing with memory chips8085 interfacing with memory chips
8085 interfacing with memory chips
 
PIC Microcontrollers
PIC MicrocontrollersPIC Microcontrollers
PIC Microcontrollers
 
HDL (hardware description language) presentation
HDL (hardware description language) presentationHDL (hardware description language) presentation
HDL (hardware description language) presentation
 
ARM Architecture
ARM ArchitectureARM Architecture
ARM Architecture
 
Microprogrammed Control Unit
Microprogrammed Control UnitMicroprogrammed Control Unit
Microprogrammed Control Unit
 
Introduction to Embedded System
Introduction to Embedded SystemIntroduction to Embedded System
Introduction to Embedded System
 
Interfacing Stepper motor with 8051
Interfacing Stepper motor with 8051Interfacing Stepper motor with 8051
Interfacing Stepper motor with 8051
 
8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil Kaware8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil Kaware
 
Design of embedded systems
Design of embedded systemsDesign of embedded systems
Design of embedded systems
 

Viewers also liked

Viewers also liked (7)

Lcd
LcdLcd
Lcd
 
Chapter 7 8051 programming in c
Chapter 7  8051 programming in cChapter 7  8051 programming in c
Chapter 7 8051 programming in c
 
8051 programming skills using EMBEDDED C
8051 programming skills using EMBEDDED C8051 programming skills using EMBEDDED C
8051 programming skills using EMBEDDED C
 
8051 full ppt
8051 full ppt8051 full ppt
8051 full ppt
 
Switches and LEDs interface to the 8051 microcontroller
Switches and LEDs interface to the 8051 microcontrollerSwitches and LEDs interface to the 8051 microcontroller
Switches and LEDs interface to the 8051 microcontroller
 
Interfacing LCD with 8051 Microcontroller
Interfacing LCD with 8051 MicrocontrollerInterfacing LCD with 8051 Microcontroller
Interfacing LCD with 8051 Microcontroller
 
Microcontroller 8051 and its interfacing
Microcontroller 8051 and its interfacingMicrocontroller 8051 and its interfacing
Microcontroller 8051 and its interfacing
 

Similar to Embedded c

Unit 3 principles of programming language
Unit 3 principles of programming languageUnit 3 principles of programming language
Unit 3 principles of programming languageVasavi College of Engg
 
Introduction to c
Introduction to cIntroduction to c
Introduction to cAjeet Kumar
 
Technical trainning.pptx
Technical trainning.pptxTechnical trainning.pptx
Technical trainning.pptxSanuSan3
 
Programming Concepts 01
Programming Concepts 01Programming Concepts 01
Programming Concepts 01Learn 2 Be
 
Functional Programming for OO Programmers (part 1)
Functional Programming for OO Programmers (part 1)Functional Programming for OO Programmers (part 1)
Functional Programming for OO Programmers (part 1)Calvin Cheng
 
04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptxManas40552
 
CBSE Class XI :- Operators in C++
CBSE Class XI :- Operators in C++CBSE Class XI :- Operators in C++
CBSE Class XI :- Operators in C++Pranav Ghildiyal
 
imperative programming language, java, android
imperative programming language, java, androidimperative programming language, java, android
imperative programming language, java, androidi i
 
operators and control statements in c language
operators and control statements in c languageoperators and control statements in c language
operators and control statements in c languageshhanks
 
Functional Programming in Ruby
Functional Programming in RubyFunctional Programming in Ruby
Functional Programming in RubyAlex Teut
 
379008-rc217-functionalprogramming
379008-rc217-functionalprogramming379008-rc217-functionalprogramming
379008-rc217-functionalprogrammingLuis Atencio
 
Bt0074 oops with java
Bt0074 oops with javaBt0074 oops with java
Bt0074 oops with javaTechglyphs
 
C++ question and answers
C++ question and answersC++ question and answers
C++ question and answersAdenKheire
 

Similar to Embedded c (20)

Unit 3 principles of programming language
Unit 3 principles of programming languageUnit 3 principles of programming language
Unit 3 principles of programming language
 
Introduction to c
Introduction to cIntroduction to c
Introduction to c
 
Technical trainning.pptx
Technical trainning.pptxTechnical trainning.pptx
Technical trainning.pptx
 
Programming Concepts 01
Programming Concepts 01Programming Concepts 01
Programming Concepts 01
 
Functional Programming for OO Programmers (part 1)
Functional Programming for OO Programmers (part 1)Functional Programming for OO Programmers (part 1)
Functional Programming for OO Programmers (part 1)
 
04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx
 
CBSE Class XI :- Operators in C++
CBSE Class XI :- Operators in C++CBSE Class XI :- Operators in C++
CBSE Class XI :- Operators in C++
 
imperative programming language, java, android
imperative programming language, java, androidimperative programming language, java, android
imperative programming language, java, android
 
operators and control statements in c language
operators and control statements in c languageoperators and control statements in c language
operators and control statements in c language
 
FUNCTION CPU
FUNCTION CPUFUNCTION CPU
FUNCTION CPU
 
Generator
GeneratorGenerator
Generator
 
SUBJECT
SUBJECTSUBJECT
SUBJECT
 
Functional Programming in Ruby
Functional Programming in RubyFunctional Programming in Ruby
Functional Programming in Ruby
 
FUNCTIONS.pptx
FUNCTIONS.pptxFUNCTIONS.pptx
FUNCTIONS.pptx
 
Training 8051Report
Training 8051ReportTraining 8051Report
Training 8051Report
 
379008-rc217-functionalprogramming
379008-rc217-functionalprogramming379008-rc217-functionalprogramming
379008-rc217-functionalprogramming
 
Bt0074 oops with java
Bt0074 oops with javaBt0074 oops with java
Bt0074 oops with java
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Functional Programming in Java
Functional Programming in JavaFunctional Programming in Java
Functional Programming in Java
 
C++ question and answers
C++ question and answersC++ question and answers
C++ question and answers
 

Embedded c

  • 2. WHAT IS EMBEDDED C? Whenever the conventional „C‟ language and its extensions are used for programming embedded systems, it is referred to as “Embedded C” programming.
  • 3. C V/S EMBEDDED C  „C‟ is a well structured,  Embedded „C‟ can be well defined and considered as a subset standardised general of conventional „C‟ purpose programming language. language.  A software program called „Cross compiler‟  A platform specific is used for the application , known as , conversion of programs compiler is used for the written in Embedded conversion of programs „C‟ to target written in C to the processor/controller target processor specific specific binary files. instructions(machine language).
  • 4. COMPILER V/S CROSS COMPILER  Compiler is a  Cross compilers are software tool that software tools used in cross platform converts a source development applications. code written in a high (In cross platform level language on top development , the of a particular compiler running on a operating system particular target processor/OS converts the running on a specific source code to machine target processor code for a target architecture. processor whose architecture and instruction set is different from the current development environment
  • 5. KEYWORDS  These are the reserved names used by the „C ‟ language.  All keywords should be written in ‘lowercase’ letters. Examples- int, char, double, float, void, while, for, long etc. ANSI „C‟ supports 32 such keywords.
  • 6. IDENTIFIERS  Identifiers are user defined names and labels.  Can contain letters of English alphabet(both upper and lower case) and numbers.  Note: The starting character of an identifier should be a letter and the only special character allowed in identifier is underscore(_).
  • 7. DATATYPES  Datatype represents the type of data held by a variable. Datatype Size(Bits) char 8 int 16 float 32 double 64 Note: The storage size may vary for data type depending on the cross compiler in use for embedded applications.
  • 8. STORAGE CLASS  Keywords related to storage class provide information on the scope i.e. visibility or accessibility and lifetime i.e. existence of a variable.  „C‟ supports four types of storage classes .
  • 9. Storage Class Meaning Comments auto Variables declared Scope and accessibility inside a function. is restricted within the Default storage class is function where the auto. variable is declared. No initialization. register Variables stored in the Same as auto in scope CPU register of and access. processor. The decision on Reduces access time of whether a variable variable. needs to be kept in CPU register of the processor depends on the compiler. static Local variable with Retains the value lifetime same as that throughout the of the program. program. By default initialises to zero on variable creation.
  • 10. Storage Class Meaning Comments static Accessibility depends on where the variable is declared. extern Variables accessible Can be modified by to all functions in a any function within a file and all files in a file or across multiple file multiple files. program.
  • 11. ARITHMETIC OPERATIONS Operator Operation Comments + Addition Adds variables or numbers - Subtraction Subtracts variables or numbers * Multiplication Multiplies variables or numbers / Division Divides variables or numbers % Remainder Finds the remainder of a division
  • 12. LOGICAL OPERATIONS  Fordecision making and program control transfer. Operator Operation Comments && Logical AND Performs logical AND operation.Output is true(logic 1) if both operands(left to right of && operator) are true.
  • 13. Operator Operation Comments || Logical OR Performs logical OR operation.Output is true(logic 1) if either operand is true. ! Logical NOT Performs logical negation.Operand is complemented.
  • 14. RELATIONAL OPEATIONS  Fordecision making and program control transfer on the basis of comparison. Operator Operation Comments < Less than Checks whether the operand on the left side of „<‟ operator is less than the operand on the right side.If yes return logic one, else return logic zero.
  • 15. Operator Operations Comments > Greater than Checks whether the operand on the left side of „>‟ operator is greater than the operand on the right side.If yes return logic one else return logic zero. <= Less than or equal to Checks whether the operand on the left side of „<=‟ operator is less than or equal to the operand on the right side.If yes return logic one, else return logic zero.
  • 16. Operator Operation Comments == Checks equality Checks whether the operand on the left side of „==‟ operator is equal to the operand on the right side.If yes return logic one, else return logic zero. != Checks non-equality Checks whether the operand on the left side of „!=‟ operator is not equal to the operand on the right side.If yes return logic one, else return logic zero.
  • 17. BRANCHING INSTRUCTIONS  CONDITIONAL  UNCONDITIONAL BRANCHING BRANCHING  Depends on  These instructions certain conditions divert program and if the execution conditions are unconditionally. met, the program execution is diverted accordingly.
  • 18. Conditional Branching Explanation instruction //if statement Evaluates the expression first and if it is true executes the statements given within the { } if(expression){ braces and continue execution of Statement 1; statements following the closing Statement 2; curly brace(}).Skips the ………………… ; execution of the statements } within the curly brace{ } if Statement 3; expression is false and continue ………………… ; execution of statements following the closing curly brace (}). One way branching
  • 19. Conditional Branching Explanation Instruction //if else statement Evaluates the expression first if(expression){ and if it is true executes the if_statement1; statements given within the { } if_statement2; braces following if (expression) ………………….. ; and continue execution of the } statements following the closing else curly brace (}) of else block. { Executes the statements within else_statement1; the curly brace { } following the else_statement2; else, if the expression is false ………………………. ; and continue execution of } statements following the closing statement 3; curly brace(}) of else.
  • 20. Conditional Branching Explanation instruction //switch case statement Tests the value of a given expression against a list of case switch(expression){ values for a matching case value 1: condition.The expression and break; case values should be case value 2: integers.value1, value2, etc. are break; integers.If a match found, default: executes the statement following break; the case and breaks from the } switch.If no match found, executes the default case. Used for multiple branching.
  • 21. Conditional branching Explanation instruction //conditional operator Used for assigning a value //?exp1:exp2 depending on the (expression) ?exp1:exp2 (expression).(expression) is calculated first and if it is E.g. greater than 0, evaluates exp1 if(x>y) and returns it as a result of A=1; operation else evaluate exp2 and else returns it as result. A=0; The return value is assigned to some variable. Can be written using conditional It is a combination of if else with operator as assignment statement. A=(x>y)1:0 Used for two way branching.
  • 22. Unconditional Branching Explanation instruction goto Goto is used as an unconditional branching instruction.goto transfers the program control indicated by a label following the goto statement.the label inicated by goto statement can be anywhere in the program either before or after the goto label instruction. goto is generally used to come out of deeply nested loops in abnormal conditions or errors.
  • 23. #include<stdio.h> void main() { int n=0; loop: ; printf("n%d", n); n++; if (n<10) { goto loop; } getch(); return 0; }
  • 24.
  • 25. LOOPING INSTRUCTIONS  For executing a particular block of code repeatedly till a condition is met or wait till an event is fired.  Used to check the status of certain I/O ports, registers, etc. and also for producing delays.  Certain devices allow write/read operations to and from some registers of the device only when the device is ready and the device ready is normally indicated by a status register or by setting/clearing certain bits of status registers.Hence the program should keep on reading the status register till the device ready indication comes.
  • 26. Looping instruction explanation //while statement Entry controlled loop statement. The expression is evaluated first while (expression){ and if it is true the body of the loop is entered and body of while loop executed.Execution of „body of while loop‟ is repeated till the } expression becomes false.
  • 27. //using while loop char *status_reg=char(*)0x3000 ; /*Declares memory mapped register*/ while(*status_reg!=0x01); /*Wait till status_reg=0x01 i.e. device ready state*/
  • 28. Looping instruction explanation //do while loop The „body of the loop‟ is executed at least once.At the do{ end of each execution of the „body of the loop‟, the while body of do loop condition (expression) is evaluated and if it is true the } loop is repeated, else loop is while(expression) terminated.
  • 29. //using do while loop char *status_reg=(char*)0x3000; do{ // body of do loop }while(*status_reg!=0x01); /* loop till status_reg=0x01 */
  • 30. Looping instruction explanation //for loop Entry controlled loop. Enters and executes „the body of for(initialisation;test for loop‟ only if the test for the condition;update variable){ condition is true. for loop contains a loop control variable body of for loop which may be initialised within the initialisation part of the } loop. Multiple variables can be initialised with „,‟ operator.
  • 31. // using for loop char *status_reg=(char*) 0x3000; for(;(*status_reg!=0x01););
  • 32.  Introduction to Embedded Systems by Shibu KV