0% found this document useful (0 votes)
8 views7 pages

Exp 3 ES

The document outlines an experiment focused on embedded programming, comparing C language and assembly language in terms of syntax, readability, performance, and memory management. It details the program generation flow, compiler stages, and components of a program image, while also providing a table of data types supported by ARM Cortex-M4 processors. Additionally, it discusses the advantages and disadvantages of high-level versus low-level programming and includes learnings from utilizing Arm mbed Studio.

Uploaded by

22cs050
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)
8 views7 pages

Exp 3 ES

The document outlines an experiment focused on embedded programming, comparing C language and assembly language in terms of syntax, readability, performance, and memory management. It details the program generation flow, compiler stages, and components of a program image, while also providing a table of data types supported by ARM Cortex-M4 processors. Additionally, it discusses the advantages and disadvantages of high-level versus low-level programming and includes learnings from utilizing Arm mbed Studio.

Uploaded by

22cs050
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/ 7

CSE-CSPIT CSE308--Embedded System

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:

i. Differentiate embedded programming using c language with reference to


assembly language.
 Compare the syntax and structure of C language with assembly language.
 Analyze the readability and maintainability of code written in C versus assembly.
 Discuss the performance and optimization aspects of both languages in
embedded systems.

C Language Assembly Language


Advantages: Advantages:
 Easy to learn  Allows direct control to
 Portable each instruction step and all
 Easy handling of complex memory
data structure  Allows direct access to
Disadvantages: instructions that cannot be
 Limited or no direct access generated with C
to core registers and stack Disadvantages:
 No direct control over  Takes a longer time to learn
instruction sequence  Difficult to manage data
generation structure
 No direct control over stack  Less portable
usage Syntax and Structure:
Syntax and Structure:  Low-level syntax, closely
 High-level syntax, more tied to hardware, uses
abstract, uses keywords and mnemonics like MOV,
constructs like for, if, while, ADD, SUB, JMP
switch  Directly interacts with CPU
 Supports functions, structs, registers, memory addresses,
unions, enums, and standard and uses labels for jumps
libraries  Uses mnemonics for
 Uses constructs like instructions (MOV, ADD)
loops(‘for’, ‘while’),  Directly manipulates
conditions(‘if’, ‘else’) registers and memory
 Variables and data types are addresses
abstracted.  Register operations: MOV
Page 1 of 7
CSE-CSPIT CSE308--Embedded System
22cs050-bindiya
 Variable declaration: int x = AX, 10
10;  Loop control: LOOP start
Readability and Maintainability: Readability and Maintainability:
 High readability due to  Low readability; requires
abstraction; code looks understanding of hardware
similar to pseudocode specifics and instruction set
 Easier to debug and  Difficult to debug; changes
maintain; changes in logic require in-depth knowledge
are straightforward of the hardware and side
 Comments and effects
documentation are more  Comments are crucial for
intuitive understanding; lack of
Performance and Optimization: documentation can make
 Suitable for complex code cryptic
applications where Performance and Optimization:
development time is critical  Enables fine-tuned
 Larger code size due to optimization specific to the
high-level abstractions hardware
 Compilers can optimize but  Smaller code size, directly
not as much as hand- translates to machine
optimized assembly instructions
Error Handling:  Enables fine-tuned
 Easier error handling with optimization specific to the
structured error management hardware.
(try, catch, return codes) Error Handling:
Memory Management:  Primitive error handling;
 Automatic memory relies on manual checking
management (with malloc, and hardware flags
free), stack and heap Memory Management:
management abstracted  Manual memory
management; direct control
over stack and heap

ii. Sketch typical program generation flow.


 Create a flowchart representing the steps from writing code to obtaining an
executable program.

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

iii. Discuss compiler stages.


 Provide a brief overview of what each stage entails and its role in the
compilation process.

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

Data Type Size Signed Number Unsigned


Number
char, int8_t, Byte -128 to 127 0 to 255
uint8_t

short, int16_t, Half word -32768 to 32767 0 to 65535


uint16_t

int, int32_t, Word -2147483648 to 0 to


uint32_t, long 2147483647 4294967295

long long, Double word -263 to 263-1 0 to 264-1


int64_t,
uint64_t

float Word -3.4028234 × 1038 to


3.4028234 × 1038

double, long Double word -


double 1.7976931348623157
×10308 to
1.7976931348623157
×10308

pointers Word 0x00 to 0xFFFFFFFF

enum Byte/ half Smallest possible


word/ word data type

bool (C++), Byte True or false


_bool(C)

wchar_t Half word 0 to 65535

vi. Compare High-level and Low-level programming.


 List the key differences between high-level and low-level programming
languages.

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

 Arm mbed Studio: In this section we see recently updated documentations


and which software are included in mbed studio.
 Installing:
 This section shows which system is required and which proxy server
support.
 It also include how to install and uninstall Mbed Studio from our
system.
 Along with above steps this section also shows how to switch to
GCC compiler
 Learn how to change preferences and setting word wrap preferences
for the editor.
 Learn how to customize keyboard shortcuts: changing keyboard
shortcuts, resetting keyboard shortcuts.
 Getting started:
 In this section I learn how to create a blinky program with given steps.

Conclusion:
Page 6 of 7
CSE-CSPIT CSE308--Embedded System
22cs050-bindiya

Page 7 of 7

You might also like