SlideShare a Scribd company logo
1 of 44
Download to read offline
Prepared by: Mohamed AbdAllah
Embedded C-Programming
Lecture 1
1
Agenda
 What are Embedded Systems?
 C for Embedded Systems vs. Embedded C.
 Code Compilation process.
 Error types.
 Code Compilation using command line.
 C language syntax quick revision.
 Task 1.
2
Agenda
3
What are Embedded Systems?
4
Introduction to Embedded Systems
 What is an embedded system ?
An embedded system is a computer system with a dedicated function within
a larger mechanical or electrical system, sometimes with real-time
computing constraints. It is embedded as part of a complete device often
including hardware and mechanical parts.
Simply, it is application-specific systems which contain hardware and
software tailored for a particular task and are generally part of a larger
system.
sensor
switch
actuator
indicator
Introduction to Embedded Systems
 Embedded systems in our life
Introduction to Embedded Systems
 Embedded systems characteristics
• Cost of hardware and software.
• Memory.
• Power consumption.
• Operator interface.
• Reliability.
• Maintainability.
• Security.
• Safety.
• Real time critical.
• Interface to environment through sensors and actuators.
Introduction to Embedded Systems
 Micro-Controller concepts
Introduction to Embedded Systems
 Micro-Controller concepts
0010011000
ADD R16,R10
SUB R7,R3
Z = x + y ;
If (y==3)
return 0 ;
file1.c Compiler
file1.asm
Assembler
file1.oLinker
file2.o
file3.o
prog.hex
Introduction to Embedded Systems
 Embedded systems market in Egypt
C for Embedded Systems vs. Embedded C
11
 C for Embedded Systems
• It is using the standard C language (mainly as described in ISO/IEC 9899
standard) but with a lot of customization and optimization to meet the
Embedded System requirements.
• C is generally used for desktop computers and can use the resources of
a desktop PC like memory, OS, etc. While C for Embedded Systems is for
microcontroller based applications so it has to deal with the limited
resources, such as RAM, ROM, I/O on an embedded processor.
 Embedded C
• It is an extension to the C standard (Under the ISO/IEC TR 18037
standard) to support specific complex topics in Embedded Systems
(Fixed point types, multiple memory areas, and I/O register mapping).
• Because Embedded C is an extension to the C standard, it uses the
same C language syntax.
12
C for Embedded Systems vs. Embedded C
Code Compilation process
13
Code Compilation process
14
Preprocessor
File.c
File.i
 Preprocessing
It is the first stage of compilation. It processes preprocessor directives like
include-files, conditional compilation instructions and macros.
 Examples on preprocessor directives:
• Including files:
#include <stdio.h>
Tells the preprocessor to copy the content of file stdio.h and paste
it here.
15
Code Compilation process
File1.c
#include “File1.h”
int x = 10;
File1.h
void myFunc1();
void myFunc1();
File1.c
void myFunc1();
void myFunc1();
int x = 10;
 Examples on preprocessor directives:
• Object-like Macro:
#define LED_PIN 10
Tells the preprocessor that whenever the symbol LED_PIN is found
inside the code, replace it with 10.
So we can type inside the code:
int x = LED_PIN; /* x will have the value 10 */
ledInit(LED_PIN); /*Initialize LED with value 10*/
#define MY_SECOND_NUMBER LED_PIN
Now MY_SECOND_NUMBER also has the value 10.
16
Code Compilation process
 Examples on preprocessor directives:
Macro definition is really helpful in code maintainability and change, for
example when a specific configuration value is used in all over the code in
a lot of lines, so to change this value only one line will be changed which is
the definition line itself instead of changing the value in all lines of code.
• Conditional compilation:
#if(LED_PIN==10)
printf(“LED_PIN=10”);
#endif
The printf line will be compiled only if the macro LED_PIN is
defined with value 10.
17
Code Compilation process
 Examples on preprocessor directives:
• Conditional compilation:
#define OPERATION_MODE 1
int main(void)
{
/* Mode of operation is decided before compilation */
#if(OPERATION_MODE==1)
startMode_1();
#elif(OPERATION_MODE==2)
startMode_2();
#else
/* Display Error message and stop process */
#error OPERATION_MODE must be 0 or 1
#endif
return 0;
}
18
Code Compilation process
 Examples on preprocessor directives:
• Conditional compilation:
#define IN_DEBUG_MODE
void testFunction(void)
{
#ifdef IN_DEBUG_MODE
printf(“DEBUG: entered testFunctionn”);
#endif
/* ANY CODE HERE */
#ifdef IN_DEBUG_MODE
printf(“DEBUG: exit testFunctionn”);
#endif
}
Debugging messages will be compiled only if IN_DEBUG_MODE is
defined.
19
Code Compilation process
 Examples on preprocessor directives:
• #undef:
Used to undefine a macro.
#define IN_DEBUG_MODE
void testFunction(void)
{
#ifdef IN_DEBUG_MODE /* This will be compiled */
printf(“DEBUG: entered testFunctionn”);
#endif
#undef IN_DEBUG_MODE /* Undefine macro */
#ifdef IN_DEBUG_MODE /* This will not be compiled */
printf(“DEBUG: exit testFunctionn”);
#endif
}
20
Code Compilation process
 Examples on preprocessor directives:
• #pragma:
The #pragma directive is the method specified by the C standard for
providing additional information to the compiler, beyond what is
conveyed in the language itself.
Example for gcc compiler:
#pragma optimize(“”, off) /* Disable any optimization */
Example for ghs compiler:
#pragma ghs section “.bss” = “.mySection”
/* It will put this array in section called “.mySection”
in memory*/
int myArray[1000];
#pragma ghs section
Note that #pragma is compiler dependent so caution shall be taken
when using it as it affects code portability. 21
Code Compilation process
Code Compilation process
22
Preprocessor Compiler
File.c
File.i File.s
 Compilation
It is the second stage. It takes the output of the preprocessor with the
source code, and generates assembly source code.
Code Compilation process
23
Preprocessor Compiler Assembler
File.c
File.i
File.o
File.s
 Assembler stage
It is the third stage of compilation. It takes the assembly source code and
produces the corresponding object code.
Code Compilation process
24
Preprocessor Compiler
File.hex
Assembler
LinkerLinker script
Library files
File.map
File.c
File.i
File.o
Other object files
File.s
 Linking
It is the final stage of compilation. It takes one or more object files or
libraries and linker script as input and combines them to produce a single
executable file. In doing so, it resolves references to external symbols,
assigns final addresses to procedures/functions and variables, and revises
code and data to reflect new addresses (a process called relocation).
Code Compilation process
25
Preprocessor Compiler
File.hex
Assembler
LinkerLinker script
Library files
File.map
File.c
File.i
File.o
Other object files
File.s
 Preprocessing
It is the first stage of compilation. It processes preprocessor directives like
include-files, conditional compilation instructions and macros.
 Compilation
It is the second stage. It takes the output of the preprocessor with the
source code, and generates assembly source code.
 Assembler stage
It is the third stage of compilation. It takes the assembly source code and
produces the corresponding object code.
 Linking
It is the final stage of compilation. It takes one or more object files or
libraries and linker script as input and combines them to produce a single
executable file. In doing so, it resolves references to external symbols,
assigns final addresses to procedures/functions and variables, and revises
code and data to reflect new addresses (a process called relocation).
26
Code Compilation process
Error types
27
 Preprocessor error
Any error that occurs during preprocessing stage, such as using undefined
macro, or finding #error directive, when this error occurs process stops
and doesn’t go to next stage.
28
Error types
File.c
#iff
int x = 10;
error: invalid preprocessing directive #iff
File.c
#error CODE NOT READY
int x = 10;
error: #error CODE NOT READY
 Compilation error (Syntax error)
Any error that occurs during compilation stage , such as using undefined
variable or miss spelling any of language words, when this error occurs
process stops and doesn’t go to next stage.
29
Error types
File.c
int x = 10;
int y = x3; error: 'x3' undeclared
File.c
int x = 10 error: expected ',' or ';' before 'int'
 Linker error
Any error that occurs during linking stage, such as using a function that the
linker can’t find in any of the object files, when this error occurs process
stops and no executable file is generated.
Example: if we compiled only File.c without any other source file:
30
Error types
File.c
int main()
{
myFunc();
return 0;
}
undefined reference to `myFunc'
 Logic error
It is an error in the program logic itself (program design or code flow) that
leads to wrong behavior during runtime, it is the most difficult error to find
as the compilation process succeeds but error occurs later at runtime.
31
Error types
File.c
int main()
{
int x = 10;
if(x > 10) /* compare is using higher than */
{
printf(“x is less than 10”); /*But logic is less than*/
funcLessThan();
}
else
{
printf(“x is higher than 10”);
funcHigherThan();
}
return 0;
}
Code Compilation using command line
32
 Environment preparing
We will be using GNU Toolchain which includes:
• GNU C Compiler (GCC).
• GNU Make.
• GNU Binutils.
• GNU Debugger (GDB).
If you are using Linux OS then all of them are available without any need
to install them, but if you are using windows then install MinGW
(Minimalist GNU for Windows), download it from:
http://www.mingw.org/
Note: It is better to install it in a folder other than "Program Files“,
probably in another partition other than C:, and make sure that
installation folder doesn’t contain any spaces.
Setup environment variable PATH to include "<MINGW_HOME>/bin"
where <MINGW_HOME> is the MinGW installed directory that you have
chosen in the previous step.
33
Code Compilation using command line
 Getting started
Now open command window in your project directory to start using these
commands
34
Code Compilation using command line
D:newProject>gcc --version
 Get gcc version
This command gets gcc installed version, if version is displayed then we are
ready to use gcc, but if command failed then make sure that program is
installed correctly and make sure that "<MINGW_HOME>/bin folder is
added to PATH environment variable in Windows.
D:newProject>gcc --help
 Get gcc help
To get help about most common options.
35
Code Compilation using command line
D:newProject>gcc file1.c file2.c -o app.exe
 Preprocess, compile, link and generate executable
To do all compilation process in one step.
D:newProject>app.exe
 Run executable
To run output application executable.
D:newProject>gcc -E file1.c -o file1.i
 Preprocess only
To do preprocessing stage only.
36
Code Compilation using command line
D:newProject>gcc -S file1.c -o file1.asm
 Compile but don’t assemble
To generate assembly code but not object code.
D:newProject>gcc -c file1.c -o file1.o
 Compile and assemble but don’t link
To generate object code but no linking occurs.
D:newProject>gcc file1.o file2.o -o app.exe
 Link object files
To link all files.
37
Code Compilation using command line
D:newProject>gcc -Wa,-adhln -g -c file1.c > out.interleaved
 Show assembly code with C code
To generate one file containing C source code interleaved with the
corresponding assembly code.
38
Code Compilation using command line
D:newProject>gcc -g file1.c file2.c -o app.exe
 Add debugging information
To add debugging information to output application executable so that this
executable can be used later by the debugger.
D:newProject>gdb app.exe
 Start program debugging
To debug application during execution using GDB, so that we can set a
break point at a specific code line to halt program, see variables values,
step in code line by line and so on.
(gdb)
Note that now command prompt changes to the following line waiting for
debugger commands:
39
Code Compilation using command line
(gdb) b file2.c:8
 Set a break point
To set a break point at a specific line of code (fore example line 8 in file2.c)
so that program execution halts when reaching this line.
(gdb) r
 Start execution
To start running application till reaching first break point set.
(gdb) c
 Continue execution
To continue running application from current break point till reaching next
break point.
40
Code Compilation using command line
(gdb) s
 Step one line
To execute one more line of code and wait.
(gdb) s 3
 Step multiple lines
To execute number of lines of code and wait (for example 3 lines).
(gdb) list
 List code lines
To display 10 lines of C source code around current break point.
41
Code Compilation using command line
(gdb) display y
 Display variable value
To display variable (for example variable called y) current value at break
point.
(gdb) quit
 Exit debugger
To exit debugger and return to command line.
D:newProject>
Note that now command prompt changes back to the original text:
C language syntax quick revision
42
Task 1
43
Mohamed AbdAllah
Embedded Systems Engineer
mohabdallah8@gmail.com
44

More Related Content

What's hot

microcontroller vs microprocessor
microcontroller vs microprocessormicrocontroller vs microprocessor
microcontroller vs microprocessorsobhadevi
 
Embedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontrollerEmbedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontrollerGaurav Verma
 
Introduction to Embedded Systems
Introduction to Embedded SystemsIntroduction to Embedded Systems
Introduction to Embedded SystemsSudhanshu Janwadkar
 
RTC Interfacing and Programming
RTC Interfacing and ProgrammingRTC Interfacing and Programming
RTC Interfacing and ProgrammingDevashish Raval
 
Pic microcontroller architecture
Pic microcontroller architecturePic microcontroller architecture
Pic microcontroller architectureDominicHendry
 
Introduction to Microcontroller
Introduction to MicrocontrollerIntroduction to Microcontroller
Introduction to MicrocontrollerNikhil Sharma
 
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
 
Introduction to the Arduino
Introduction to the ArduinoIntroduction to the Arduino
Introduction to the ArduinoWingston
 
Introduction to AVR Microcontroller
Introduction to AVR Microcontroller Introduction to AVR Microcontroller
Introduction to AVR Microcontroller Mahmoud Sadat
 
Microprocessors & Microcomputers Lecture Notes
Microprocessors & Microcomputers Lecture NotesMicroprocessors & Microcomputers Lecture Notes
Microprocessors & Microcomputers Lecture NotesFellowBuddy.com
 
8051 Microcontroller ppt
8051 Microcontroller ppt8051 Microcontroller ppt
8051 Microcontroller pptRahul Kumar
 

What's hot (20)

Embedded system
Embedded systemEmbedded system
Embedded system
 
Embedded System Basics
Embedded System BasicsEmbedded System Basics
Embedded System Basics
 
microcontroller vs microprocessor
microcontroller vs microprocessormicrocontroller vs microprocessor
microcontroller vs microprocessor
 
Embedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontrollerEmbedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontroller
 
Introduction to Embedded Systems
Introduction to Embedded SystemsIntroduction to Embedded Systems
Introduction to Embedded Systems
 
PIC Microcontrollers
PIC MicrocontrollersPIC Microcontrollers
PIC Microcontrollers
 
RTC Interfacing and Programming
RTC Interfacing and ProgrammingRTC Interfacing and Programming
RTC Interfacing and Programming
 
Embedded C - Lecture 3
Embedded C - Lecture 3Embedded C - Lecture 3
Embedded C - Lecture 3
 
Pic microcontroller architecture
Pic microcontroller architecturePic microcontroller architecture
Pic microcontroller architecture
 
Introduction to Microcontroller
Introduction to MicrocontrollerIntroduction to Microcontroller
Introduction to Microcontroller
 
Embedded C - Optimization techniques
Embedded C - Optimization techniquesEmbedded C - Optimization techniques
Embedded C - Optimization techniques
 
Timing diagram 8085 microprocessor
Timing diagram 8085 microprocessorTiming diagram 8085 microprocessor
Timing diagram 8085 microprocessor
 
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
 
Embedded C workshop
Embedded C workshopEmbedded C workshop
Embedded C workshop
 
Introduction to the Arduino
Introduction to the ArduinoIntroduction to the Arduino
Introduction to the Arduino
 
Embedded system
Embedded systemEmbedded system
Embedded system
 
Introduction to AVR Microcontroller
Introduction to AVR Microcontroller Introduction to AVR Microcontroller
Introduction to AVR Microcontroller
 
Unit 3 mpmc
Unit 3 mpmcUnit 3 mpmc
Unit 3 mpmc
 
Microprocessors & Microcomputers Lecture Notes
Microprocessors & Microcomputers Lecture NotesMicroprocessors & Microcomputers Lecture Notes
Microprocessors & Microcomputers Lecture Notes
 
8051 Microcontroller ppt
8051 Microcontroller ppt8051 Microcontroller ppt
8051 Microcontroller ppt
 

Viewers also liked

C Programming For Embedded Systems
C Programming For Embedded SystemsC Programming For Embedded Systems
C Programming For Embedded SystemsGanesh Samarthyam
 
I2C programming with C and Arduino
I2C programming with C and ArduinoI2C programming with C and Arduino
I2C programming with C and Arduinosato262
 
Object-Oriented Design: Multiple inheritance (C++ and C#)
Object-Oriented Design: Multiple inheritance (C++ and C#)Object-Oriented Design: Multiple inheritance (C++ and C#)
Object-Oriented Design: Multiple inheritance (C++ and C#)Adair Dingle
 
Compiler in System Programming/Code Optimization techniques in System Program...
Compiler in System Programming/Code Optimization techniques in System Program...Compiler in System Programming/Code Optimization techniques in System Program...
Compiler in System Programming/Code Optimization techniques in System Program...Janki Shah
 
Protols used in bluetooth
Protols used in bluetoothProtols used in bluetooth
Protols used in bluetoothSonali Parab
 
Serial Peripheral Interface
Serial Peripheral InterfaceSerial Peripheral Interface
Serial Peripheral InterfaceAnurag Tomar
 
Arm developement
Arm developementArm developement
Arm developementhirokiht
 
Multiple Inheritance
Multiple InheritanceMultiple Inheritance
Multiple Inheritanceadil raja
 
I2C Bus (Inter-Integrated Circuit)
I2C Bus (Inter-Integrated Circuit)I2C Bus (Inter-Integrated Circuit)
I2C Bus (Inter-Integrated Circuit)Varun Mahajan
 
Serial peripheral interface
Serial peripheral interfaceSerial peripheral interface
Serial peripheral interfaceAbhijeet kapse
 
Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)Dhaval Kaneria
 
Code Optimization
Code OptimizationCode Optimization
Code Optimizationguest9f8315
 

Viewers also liked (19)

C Programming For Embedded Systems
C Programming For Embedded SystemsC Programming For Embedded Systems
C Programming For Embedded Systems
 
I2C programming with C and Arduino
I2C programming with C and ArduinoI2C programming with C and Arduino
I2C programming with C and Arduino
 
Arm processor
Arm processorArm processor
Arm processor
 
Inheritance in OOPS
Inheritance in OOPSInheritance in OOPS
Inheritance in OOPS
 
Object-Oriented Design: Multiple inheritance (C++ and C#)
Object-Oriented Design: Multiple inheritance (C++ and C#)Object-Oriented Design: Multiple inheritance (C++ and C#)
Object-Oriented Design: Multiple inheritance (C++ and C#)
 
Introduction to Embedded System
Introduction to Embedded SystemIntroduction to Embedded System
Introduction to Embedded System
 
Compiler in System Programming/Code Optimization techniques in System Program...
Compiler in System Programming/Code Optimization techniques in System Program...Compiler in System Programming/Code Optimization techniques in System Program...
Compiler in System Programming/Code Optimization techniques in System Program...
 
Protols used in bluetooth
Protols used in bluetoothProtols used in bluetooth
Protols used in bluetooth
 
Serial Peripheral Interface
Serial Peripheral InterfaceSerial Peripheral Interface
Serial Peripheral Interface
 
Arm developement
Arm developementArm developement
Arm developement
 
Multiple Inheritance
Multiple InheritanceMultiple Inheritance
Multiple Inheritance
 
SPI Protocol
SPI ProtocolSPI Protocol
SPI Protocol
 
I2C Protocol
I2C ProtocolI2C Protocol
I2C Protocol
 
Embedded C
Embedded CEmbedded C
Embedded C
 
I2C Bus (Inter-Integrated Circuit)
I2C Bus (Inter-Integrated Circuit)I2C Bus (Inter-Integrated Circuit)
I2C Bus (Inter-Integrated Circuit)
 
Serial peripheral interface
Serial peripheral interfaceSerial peripheral interface
Serial peripheral interface
 
Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)Serial Peripheral Interface(SPI)
Serial Peripheral Interface(SPI)
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
 
Iot
IotIot
Iot
 

Similar to Embedded C - Lecture 1

embeddedc-lecture1-160404055102.pptx
embeddedc-lecture1-160404055102.pptxembeddedc-lecture1-160404055102.pptx
embeddedc-lecture1-160404055102.pptxsangeetaSS
 
C Programming UNIT 1.pptx
C Programming  UNIT 1.pptxC Programming  UNIT 1.pptx
C Programming UNIT 1.pptxMugilvannan11
 
CS8251_QB_answers.pdf
CS8251_QB_answers.pdfCS8251_QB_answers.pdf
CS8251_QB_answers.pdfvino108206
 
Concisely describe the following terms 40 1. Source code 2. Object c.pdf
Concisely describe the following terms 40 1. Source code 2. Object c.pdfConcisely describe the following terms 40 1. Source code 2. Object c.pdf
Concisely describe the following terms 40 1. Source code 2. Object c.pdffeelinggift
 
introduction of c langauge(I unit)
introduction of c langauge(I unit)introduction of c langauge(I unit)
introduction of c langauge(I unit)Prashant Sharma
 
Diploma ii cfpc u-1 introduction to c language
Diploma ii  cfpc u-1 introduction to c languageDiploma ii  cfpc u-1 introduction to c language
Diploma ii cfpc u-1 introduction to c languageRai University
 
Btech i pic u-1 introduction to c language
Btech i pic u-1 introduction to c languageBtech i pic u-1 introduction to c language
Btech i pic u-1 introduction to c languageRai University
 
C++ advanced PPT.pdf
C++ advanced PPT.pdfC++ advanced PPT.pdf
C++ advanced PPT.pdfDinashMaliya3
 
Build process in ST Visual Develop
Build process in ST Visual DevelopBuild process in ST Visual Develop
Build process in ST Visual DevelopGourav Kumar
 
Bsc cs i pic u-1 introduction to c language
Bsc cs i pic u-1 introduction to c languageBsc cs i pic u-1 introduction to c language
Bsc cs i pic u-1 introduction to c languageRai University
 
Mca i pic u-1 introduction to c language
Mca i pic u-1 introduction to c languageMca i pic u-1 introduction to c language
Mca i pic u-1 introduction to c languageRai University
 
Introduction of c language
Introduction of c languageIntroduction of c language
Introduction of c languagefarishah
 

Similar to Embedded C - Lecture 1 (20)

embeddedc-lecture1-160404055102.pptx
embeddedc-lecture1-160404055102.pptxembeddedc-lecture1-160404055102.pptx
embeddedc-lecture1-160404055102.pptx
 
C Programming UNIT 1.pptx
C Programming  UNIT 1.pptxC Programming  UNIT 1.pptx
C Programming UNIT 1.pptx
 
Activity 5
Activity 5Activity 5
Activity 5
 
CS8251_QB_answers.pdf
CS8251_QB_answers.pdfCS8251_QB_answers.pdf
CS8251_QB_answers.pdf
 
Concisely describe the following terms 40 1. Source code 2. Object c.pdf
Concisely describe the following terms 40 1. Source code 2. Object c.pdfConcisely describe the following terms 40 1. Source code 2. Object c.pdf
Concisely describe the following terms 40 1. Source code 2. Object c.pdf
 
Prog1-L1.pdf
Prog1-L1.pdfProg1-L1.pdf
Prog1-L1.pdf
 
Srgoc dotnet
Srgoc dotnetSrgoc dotnet
Srgoc dotnet
 
C++ basics
C++ basicsC++ basics
C++ basics
 
introduction of c langauge(I unit)
introduction of c langauge(I unit)introduction of c langauge(I unit)
introduction of c langauge(I unit)
 
Diploma ii cfpc u-1 introduction to c language
Diploma ii  cfpc u-1 introduction to c languageDiploma ii  cfpc u-1 introduction to c language
Diploma ii cfpc u-1 introduction to c language
 
Readme
ReadmeReadme
Readme
 
Btech i pic u-1 introduction to c language
Btech i pic u-1 introduction to c languageBtech i pic u-1 introduction to c language
Btech i pic u-1 introduction to c language
 
C++Basics2022.pptx
C++Basics2022.pptxC++Basics2022.pptx
C++Basics2022.pptx
 
C++ advanced PPT.pdf
C++ advanced PPT.pdfC++ advanced PPT.pdf
C++ advanced PPT.pdf
 
Embedded C.pptx
Embedded C.pptxEmbedded C.pptx
Embedded C.pptx
 
Build process in ST Visual Develop
Build process in ST Visual DevelopBuild process in ST Visual Develop
Build process in ST Visual Develop
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Bsc cs i pic u-1 introduction to c language
Bsc cs i pic u-1 introduction to c languageBsc cs i pic u-1 introduction to c language
Bsc cs i pic u-1 introduction to c language
 
Mca i pic u-1 introduction to c language
Mca i pic u-1 introduction to c languageMca i pic u-1 introduction to c language
Mca i pic u-1 introduction to c language
 
Introduction of c language
Introduction of c languageIntroduction of c language
Introduction of c language
 

More from Mohamed Abdallah

Hardware interfacing basics using AVR
Hardware interfacing basics using AVRHardware interfacing basics using AVR
Hardware interfacing basics using AVRMohamed Abdallah
 
Raspberry Pi - Lecture 6 Working on Raspberry Pi
Raspberry Pi - Lecture 6 Working on Raspberry PiRaspberry Pi - Lecture 6 Working on Raspberry Pi
Raspberry Pi - Lecture 6 Working on Raspberry PiMohamed Abdallah
 
Raspberry Pi - Lecture 5 Python for Raspberry Pi
Raspberry Pi - Lecture 5 Python for Raspberry PiRaspberry Pi - Lecture 5 Python for Raspberry Pi
Raspberry Pi - Lecture 5 Python for Raspberry PiMohamed Abdallah
 
Raspberry Pi - Lecture 4 Hardware Interfacing Special Cases
Raspberry Pi - Lecture 4 Hardware Interfacing Special CasesRaspberry Pi - Lecture 4 Hardware Interfacing Special Cases
Raspberry Pi - Lecture 4 Hardware Interfacing Special CasesMohamed Abdallah
 
Raspberry Pi - Lecture 3 Embedded Communication Protocols
Raspberry Pi - Lecture 3 Embedded Communication ProtocolsRaspberry Pi - Lecture 3 Embedded Communication Protocols
Raspberry Pi - Lecture 3 Embedded Communication ProtocolsMohamed Abdallah
 
Raspberry Pi - Lecture 2 Linux OS
Raspberry Pi - Lecture 2 Linux OSRaspberry Pi - Lecture 2 Linux OS
Raspberry Pi - Lecture 2 Linux OSMohamed Abdallah
 
Raspberry Pi - Lecture 1 Introduction
Raspberry Pi - Lecture 1 IntroductionRaspberry Pi - Lecture 1 Introduction
Raspberry Pi - Lecture 1 IntroductionMohamed Abdallah
 

More from Mohamed Abdallah (8)

Hardware interfacing basics using AVR
Hardware interfacing basics using AVRHardware interfacing basics using AVR
Hardware interfacing basics using AVR
 
Embedded C - Lecture 4
Embedded C - Lecture 4Embedded C - Lecture 4
Embedded C - Lecture 4
 
Raspberry Pi - Lecture 6 Working on Raspberry Pi
Raspberry Pi - Lecture 6 Working on Raspberry PiRaspberry Pi - Lecture 6 Working on Raspberry Pi
Raspberry Pi - Lecture 6 Working on Raspberry Pi
 
Raspberry Pi - Lecture 5 Python for Raspberry Pi
Raspberry Pi - Lecture 5 Python for Raspberry PiRaspberry Pi - Lecture 5 Python for Raspberry Pi
Raspberry Pi - Lecture 5 Python for Raspberry Pi
 
Raspberry Pi - Lecture 4 Hardware Interfacing Special Cases
Raspberry Pi - Lecture 4 Hardware Interfacing Special CasesRaspberry Pi - Lecture 4 Hardware Interfacing Special Cases
Raspberry Pi - Lecture 4 Hardware Interfacing Special Cases
 
Raspberry Pi - Lecture 3 Embedded Communication Protocols
Raspberry Pi - Lecture 3 Embedded Communication ProtocolsRaspberry Pi - Lecture 3 Embedded Communication Protocols
Raspberry Pi - Lecture 3 Embedded Communication Protocols
 
Raspberry Pi - Lecture 2 Linux OS
Raspberry Pi - Lecture 2 Linux OSRaspberry Pi - Lecture 2 Linux OS
Raspberry Pi - Lecture 2 Linux OS
 
Raspberry Pi - Lecture 1 Introduction
Raspberry Pi - Lecture 1 IntroductionRaspberry Pi - Lecture 1 Introduction
Raspberry Pi - Lecture 1 Introduction
 

Recently uploaded

MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGSIVASHANKAR N
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 

Recently uploaded (20)

MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 

Embedded C - Lecture 1

  • 1. Prepared by: Mohamed AbdAllah Embedded C-Programming Lecture 1 1
  • 2. Agenda  What are Embedded Systems?  C for Embedded Systems vs. Embedded C.  Code Compilation process.  Error types.  Code Compilation using command line.  C language syntax quick revision.  Task 1. 2
  • 4. What are Embedded Systems? 4
  • 5. Introduction to Embedded Systems  What is an embedded system ? An embedded system is a computer system with a dedicated function within a larger mechanical or electrical system, sometimes with real-time computing constraints. It is embedded as part of a complete device often including hardware and mechanical parts. Simply, it is application-specific systems which contain hardware and software tailored for a particular task and are generally part of a larger system. sensor switch actuator indicator
  • 6. Introduction to Embedded Systems  Embedded systems in our life
  • 7. Introduction to Embedded Systems  Embedded systems characteristics • Cost of hardware and software. • Memory. • Power consumption. • Operator interface. • Reliability. • Maintainability. • Security. • Safety. • Real time critical. • Interface to environment through sensors and actuators.
  • 8. Introduction to Embedded Systems  Micro-Controller concepts
  • 9. Introduction to Embedded Systems  Micro-Controller concepts 0010011000 ADD R16,R10 SUB R7,R3 Z = x + y ; If (y==3) return 0 ; file1.c Compiler file1.asm Assembler file1.oLinker file2.o file3.o prog.hex
  • 10. Introduction to Embedded Systems  Embedded systems market in Egypt
  • 11. C for Embedded Systems vs. Embedded C 11
  • 12.  C for Embedded Systems • It is using the standard C language (mainly as described in ISO/IEC 9899 standard) but with a lot of customization and optimization to meet the Embedded System requirements. • C is generally used for desktop computers and can use the resources of a desktop PC like memory, OS, etc. While C for Embedded Systems is for microcontroller based applications so it has to deal with the limited resources, such as RAM, ROM, I/O on an embedded processor.  Embedded C • It is an extension to the C standard (Under the ISO/IEC TR 18037 standard) to support specific complex topics in Embedded Systems (Fixed point types, multiple memory areas, and I/O register mapping). • Because Embedded C is an extension to the C standard, it uses the same C language syntax. 12 C for Embedded Systems vs. Embedded C
  • 14. Code Compilation process 14 Preprocessor File.c File.i  Preprocessing It is the first stage of compilation. It processes preprocessor directives like include-files, conditional compilation instructions and macros.
  • 15.  Examples on preprocessor directives: • Including files: #include <stdio.h> Tells the preprocessor to copy the content of file stdio.h and paste it here. 15 Code Compilation process File1.c #include “File1.h” int x = 10; File1.h void myFunc1(); void myFunc1(); File1.c void myFunc1(); void myFunc1(); int x = 10;
  • 16.  Examples on preprocessor directives: • Object-like Macro: #define LED_PIN 10 Tells the preprocessor that whenever the symbol LED_PIN is found inside the code, replace it with 10. So we can type inside the code: int x = LED_PIN; /* x will have the value 10 */ ledInit(LED_PIN); /*Initialize LED with value 10*/ #define MY_SECOND_NUMBER LED_PIN Now MY_SECOND_NUMBER also has the value 10. 16 Code Compilation process
  • 17.  Examples on preprocessor directives: Macro definition is really helpful in code maintainability and change, for example when a specific configuration value is used in all over the code in a lot of lines, so to change this value only one line will be changed which is the definition line itself instead of changing the value in all lines of code. • Conditional compilation: #if(LED_PIN==10) printf(“LED_PIN=10”); #endif The printf line will be compiled only if the macro LED_PIN is defined with value 10. 17 Code Compilation process
  • 18.  Examples on preprocessor directives: • Conditional compilation: #define OPERATION_MODE 1 int main(void) { /* Mode of operation is decided before compilation */ #if(OPERATION_MODE==1) startMode_1(); #elif(OPERATION_MODE==2) startMode_2(); #else /* Display Error message and stop process */ #error OPERATION_MODE must be 0 or 1 #endif return 0; } 18 Code Compilation process
  • 19.  Examples on preprocessor directives: • Conditional compilation: #define IN_DEBUG_MODE void testFunction(void) { #ifdef IN_DEBUG_MODE printf(“DEBUG: entered testFunctionn”); #endif /* ANY CODE HERE */ #ifdef IN_DEBUG_MODE printf(“DEBUG: exit testFunctionn”); #endif } Debugging messages will be compiled only if IN_DEBUG_MODE is defined. 19 Code Compilation process
  • 20.  Examples on preprocessor directives: • #undef: Used to undefine a macro. #define IN_DEBUG_MODE void testFunction(void) { #ifdef IN_DEBUG_MODE /* This will be compiled */ printf(“DEBUG: entered testFunctionn”); #endif #undef IN_DEBUG_MODE /* Undefine macro */ #ifdef IN_DEBUG_MODE /* This will not be compiled */ printf(“DEBUG: exit testFunctionn”); #endif } 20 Code Compilation process
  • 21.  Examples on preprocessor directives: • #pragma: The #pragma directive is the method specified by the C standard for providing additional information to the compiler, beyond what is conveyed in the language itself. Example for gcc compiler: #pragma optimize(“”, off) /* Disable any optimization */ Example for ghs compiler: #pragma ghs section “.bss” = “.mySection” /* It will put this array in section called “.mySection” in memory*/ int myArray[1000]; #pragma ghs section Note that #pragma is compiler dependent so caution shall be taken when using it as it affects code portability. 21 Code Compilation process
  • 22. Code Compilation process 22 Preprocessor Compiler File.c File.i File.s  Compilation It is the second stage. It takes the output of the preprocessor with the source code, and generates assembly source code.
  • 23. Code Compilation process 23 Preprocessor Compiler Assembler File.c File.i File.o File.s  Assembler stage It is the third stage of compilation. It takes the assembly source code and produces the corresponding object code.
  • 24. Code Compilation process 24 Preprocessor Compiler File.hex Assembler LinkerLinker script Library files File.map File.c File.i File.o Other object files File.s  Linking It is the final stage of compilation. It takes one or more object files or libraries and linker script as input and combines them to produce a single executable file. In doing so, it resolves references to external symbols, assigns final addresses to procedures/functions and variables, and revises code and data to reflect new addresses (a process called relocation).
  • 25. Code Compilation process 25 Preprocessor Compiler File.hex Assembler LinkerLinker script Library files File.map File.c File.i File.o Other object files File.s
  • 26.  Preprocessing It is the first stage of compilation. It processes preprocessor directives like include-files, conditional compilation instructions and macros.  Compilation It is the second stage. It takes the output of the preprocessor with the source code, and generates assembly source code.  Assembler stage It is the third stage of compilation. It takes the assembly source code and produces the corresponding object code.  Linking It is the final stage of compilation. It takes one or more object files or libraries and linker script as input and combines them to produce a single executable file. In doing so, it resolves references to external symbols, assigns final addresses to procedures/functions and variables, and revises code and data to reflect new addresses (a process called relocation). 26 Code Compilation process
  • 28.  Preprocessor error Any error that occurs during preprocessing stage, such as using undefined macro, or finding #error directive, when this error occurs process stops and doesn’t go to next stage. 28 Error types File.c #iff int x = 10; error: invalid preprocessing directive #iff File.c #error CODE NOT READY int x = 10; error: #error CODE NOT READY
  • 29.  Compilation error (Syntax error) Any error that occurs during compilation stage , such as using undefined variable or miss spelling any of language words, when this error occurs process stops and doesn’t go to next stage. 29 Error types File.c int x = 10; int y = x3; error: 'x3' undeclared File.c int x = 10 error: expected ',' or ';' before 'int'
  • 30.  Linker error Any error that occurs during linking stage, such as using a function that the linker can’t find in any of the object files, when this error occurs process stops and no executable file is generated. Example: if we compiled only File.c without any other source file: 30 Error types File.c int main() { myFunc(); return 0; } undefined reference to `myFunc'
  • 31.  Logic error It is an error in the program logic itself (program design or code flow) that leads to wrong behavior during runtime, it is the most difficult error to find as the compilation process succeeds but error occurs later at runtime. 31 Error types File.c int main() { int x = 10; if(x > 10) /* compare is using higher than */ { printf(“x is less than 10”); /*But logic is less than*/ funcLessThan(); } else { printf(“x is higher than 10”); funcHigherThan(); } return 0; }
  • 32. Code Compilation using command line 32
  • 33.  Environment preparing We will be using GNU Toolchain which includes: • GNU C Compiler (GCC). • GNU Make. • GNU Binutils. • GNU Debugger (GDB). If you are using Linux OS then all of them are available without any need to install them, but if you are using windows then install MinGW (Minimalist GNU for Windows), download it from: http://www.mingw.org/ Note: It is better to install it in a folder other than "Program Files“, probably in another partition other than C:, and make sure that installation folder doesn’t contain any spaces. Setup environment variable PATH to include "<MINGW_HOME>/bin" where <MINGW_HOME> is the MinGW installed directory that you have chosen in the previous step. 33 Code Compilation using command line
  • 34.  Getting started Now open command window in your project directory to start using these commands 34 Code Compilation using command line D:newProject>gcc --version  Get gcc version This command gets gcc installed version, if version is displayed then we are ready to use gcc, but if command failed then make sure that program is installed correctly and make sure that "<MINGW_HOME>/bin folder is added to PATH environment variable in Windows. D:newProject>gcc --help  Get gcc help To get help about most common options.
  • 35. 35 Code Compilation using command line D:newProject>gcc file1.c file2.c -o app.exe  Preprocess, compile, link and generate executable To do all compilation process in one step. D:newProject>app.exe  Run executable To run output application executable. D:newProject>gcc -E file1.c -o file1.i  Preprocess only To do preprocessing stage only.
  • 36. 36 Code Compilation using command line D:newProject>gcc -S file1.c -o file1.asm  Compile but don’t assemble To generate assembly code but not object code. D:newProject>gcc -c file1.c -o file1.o  Compile and assemble but don’t link To generate object code but no linking occurs. D:newProject>gcc file1.o file2.o -o app.exe  Link object files To link all files.
  • 37. 37 Code Compilation using command line D:newProject>gcc -Wa,-adhln -g -c file1.c > out.interleaved  Show assembly code with C code To generate one file containing C source code interleaved with the corresponding assembly code.
  • 38. 38 Code Compilation using command line D:newProject>gcc -g file1.c file2.c -o app.exe  Add debugging information To add debugging information to output application executable so that this executable can be used later by the debugger. D:newProject>gdb app.exe  Start program debugging To debug application during execution using GDB, so that we can set a break point at a specific code line to halt program, see variables values, step in code line by line and so on. (gdb) Note that now command prompt changes to the following line waiting for debugger commands:
  • 39. 39 Code Compilation using command line (gdb) b file2.c:8  Set a break point To set a break point at a specific line of code (fore example line 8 in file2.c) so that program execution halts when reaching this line. (gdb) r  Start execution To start running application till reaching first break point set. (gdb) c  Continue execution To continue running application from current break point till reaching next break point.
  • 40. 40 Code Compilation using command line (gdb) s  Step one line To execute one more line of code and wait. (gdb) s 3  Step multiple lines To execute number of lines of code and wait (for example 3 lines). (gdb) list  List code lines To display 10 lines of C source code around current break point.
  • 41. 41 Code Compilation using command line (gdb) display y  Display variable value To display variable (for example variable called y) current value at break point. (gdb) quit  Exit debugger To exit debugger and return to command line. D:newProject> Note that now command prompt changes back to the original text:
  • 42. C language syntax quick revision 42
  • 44. Mohamed AbdAllah Embedded Systems Engineer mohabdallah8@gmail.com 44