Exp 3 ES
Exp 3 ES
22cs050-bindiya
Date:
EXPERIMENT NO. 3
AIM: To explore embedded programming in C versus assembly language, understand
program generation flow and compiler stages, investigate program images, document ARM
Cortex-M4 data types, compare high-level and low-level programming, and utilize ARM
mbed studio for development.
Objectives:
Ans: The development flow for generating a program follows these steps:
1. Compile: Convert source code into assembly code.
2. Assemble: Translate assembly code into machine code, producing object files.
3. Link: Combine object files into a single executable file (program image).
4. Download: Transfer the executable file to the program memory (typically on-
chip flash memory) for the processor to execute.
Page 2 of 7
CSE-CSPIT CSE308--Embedded System
22cs050-bindiya
Ans: Compiler stages with its role in the compilation process as below:
1. Pre-processing:
• Replaces macros, defined by an initial hash-tag (#) in the code
• Merges all subfiles (.c, .h) to one complete file
2. Parser:
• Reads in C code
• Checks for syntax errors
• Forms intermediate code (tree representation)
3. High-Level Optimizer:
• Modifies intermediate code (processor-independent)
4. Code Generator:
• Creates assembly code step-by-step from each node of the intermediate code
• Allocates variable uses to registers
5. Low-Level Optimizer:
• Modifies assembly code (parts are processor-specific)
6. Assembler:
• Creates object code (machine code)
7. Linker/Loader:
• Creates executable image from object file
iv. What is a program image? What does it contain? Write in brief about the
components of the program image.
Program Image: The program image (sometimes also called the executable file)
Page 3 of 7
CSE-CSPIT CSE308--Embedded System
22cs050-bindiya
refers to a piece of fully integrated code that is ready to execute.
The program image includes:
1. Vector table:
• Contains the starting addresses of exceptions (vectors) and the value
of the main stack point (MSP)
2. C start-up routine:
• Used to set up data memory and the initialization of values for global
data variables
• Is inserted by the compiler/linker automatically, labeled as ‘__main’
by the Arm compiler, or ‘__start’ by the GNU C compiler
3. Program code:
• Program code refers to the instructions generated from the application
program. Data types include:
• Initial values of variables: the local variables that are initialized in
functions or subroutines during program execution time
• Constants: used in data values, address of peripherals, character
strings, etc.
• Sometimes stored together in data blocks called literal pools
• Constant data such as lookup tables, graphics image data (e.g.,
bit map) can be merged into the program images
4. C library code:
• Object codes inserted into the program image by linkers
v. Prepare a table for data types supported by Arm cortex M4 processors along
with its size, signed number range and unsigned number range.
Page 4 of 7
CSE-CSPIT CSE308--Embedded System
22cs050-bindiya
Page 5 of 7
CSE-CSPIT CSE308--Embedded System
22cs050-bindiya
Discuss the advantages and disadvantages of using each type in an embedded
system
High Level Language Low Level Language
Advantages: Advantages:
1. Higher productivity (less 1. More optimized code and
development time) memory efficient
2. Portability across devices 2. Less translation time for
3. Resulting code that is easier source to machine code
code to read and maintain 3. Directly talk to hardware
4. Allows reuse of code
5. Rapid prototyping of
applications
Disadvantages: Disadvantages:
1. Less optimized code 1. Less portability from one
2. Additional translation time for device to another
source to machine code 2. Resulting code is more
3. Another level of abstraction to difficult for others to read,
deal with reuse, and maintain
3. Low productivity
vii. Learn how to utilize Arm mbed studio from the link and list out your learnings
using bullet points: https://os.mbed.com/docs/mbed-
studio/current/introduction/index.html
Conclusion:
Page 6 of 7
CSE-CSPIT CSE308--Embedded System
22cs050-bindiya
Page 7 of 7