Unit 5th
Unit 5th
v=PcDWm7J19Vo
Can loaded
1. Mixing Assembly Language with High level language like ‘C’ (Assembly Language with ‘C’)
Assembly routines are mixed with ‘C’ in situations where the entire program is written in ‘C’ and
the cross compiler in use do not have built in support for implementing certain features like ISR.
If the programmer wants to take advantage of the speed and optimized code offered by the
machine code generated by hand written assembly rather than cross compiler generated
machine code.
For accessing certain low level hardware, the timing specifications may be very critical and cross
compiler generated machine code may not be able to offer the required time specifications
accurately.
The programmer must be aware of how to pass parameters from the ‘C’ routine to assembly and
values returned from assembly routine to ‘C’ and how Assembly routine is invoked from the ‘C’
code.
Passing parameter to the assembly routine and returning values from the assembly routine to
the caller ‘C’ function and the method of invoking the assembly routine from ‘C’ code is cross
compiler dependent.
2. Mixing High level language like ‘C’ with Assembly Language (‘C’ with Assembly Language)
The source code is already available in assembly language and routine written in a high level
language needs to be included to the existing code.
The entire source code is planned in Assembly code for various reasons like optimized code,
optimal performance, efficient code memory utilization and proven expertise in handling the
assembly.
The functions written in ‘C’ use parameter passing to the function and returns values to the
calling functions.
The programmer must be aware of how parameters are passed to the function and how
values returned from the function and how function is invoked from the assembly language
environment.
Passing parameter to the function and returning values from the function using CPU registers
, stack memory and fixed memory.
Cross compiler->https://medium.com/@harsh.bihani20/cross-compiler-and-its-
applications-37b6b7c76d36
https://www.quora.com/What-is-meant-by-cross-compilation-in-an-embedded-system
https://allthingsembedded.com/2018/12/29/cross-compiling-for-embedded-devices/
GCC is an acronym for GNU Compiler Collection. It is not just a compiler, but also some
other assorted tools that let you manipulate executable files and generate binaries in
multiple formats. The C compiler in GCC is also called gcc (GNU C Compiler), whilst the C+
+ compiler is a binary named g++.
The job of the compiler is to take source code and transform it into some object code that
is able to run on the target platform. This is done in a few separate steps:
Preprocessing:
o The first step is running the C Preprocessor on each of the source files. This
will replace all preprocessor directives such as #define and #include,
creating a final file that can be parsed by the compiler itself. It substitutes
all define directives and includes all header files in the source file, as well as
handling some compile time conditional statements such as #ifdef.
o GCC can run this phase using the cpp command.
Compilation:
o This stage takes care of translating all the source code to the assembly
language required for the target processor. The compiler usually translates
the source code first into an intermediate representation that can be
interpreted by the optimizer and with which it can decide to make
optimizations on the code to reduce the size of it and increase
performance. Later, this intermediate representation is translated into the
ASM language used for the target language. Function names and variable
names are translated into symbols that are exported whenever it is
necessary. Unresolved symbols will be taken care of later in the build
process.
o GCC can run this phase using the gcc -S or g++ -S commands
Assembly:
o Once the code for each source file has been transformed into ASM files, the
assembler can run and convert each of the instructions into machine code
or object code that can be run directly on the target. In addition to the
machine code, the object file also includes information about the symbols
required and contained within the code.
o GCC uses the as command to assemble the ASM sources.
Linkage:
o The last step in this process is the running the linker. This step takes care of
resolving missing symbols and can perform optimizations such as removing
unused code and data. It basically merges all object files into a single
executable. The linker can also link other code contained in libraries (static
or shared).
Q)explain cross compilation. Discuss its need and importance for embedded and real time system
design
ans. Cross-compilation is the process of compiling code on one platform (the host)
for execution on a different platform (the target). In embedded and real-time system
design, cross-compilation is crucial due to several reasons:
1 - Native Toolchain:
Native toolchains are designed and optimized for a particular hardware or software
platform. They are intended to run on the same platform for which they generate
code.
Examples: Compilers like GCC (GNU Compiler Collection) or Microsoft Visual C++
are native toolchains. They compile code to run specifically on the host system where
the compiler is installed.
2 - Cross-Platform Toolchain:
https://www.linkedin.com/pulse/buildingcompilation-process-using-gnu-arm-toolchain-
mohamed-ali/
• Cross-compilation is the process of converting a source code written in high level language to a
target processor/controller understandable machine code.
• List file(.lst)
• Hex file(.hex)
• Map file(.MAP)
• Object file(.obj)
• Symbol tables
• Contains the pre-processor output for the pre-processor instructions used in the source file.
Map File(.MAP)
• Linking and locating of relocatable object files generate a list file called ‘linker list file’
or ‘map file’.
•Page header
• Command line
• CPU details
• Input modules
• Memory map
• Program size
HEX File(.HEX)
• Hex file is the binary executable file created from the source code.
• Intel HEX and Motorola HEX are the two commonly used hex file formats in embedded
applications.
Disassembler/Decompiler
• Disassembler is a utility program which converts machine code into target processor specific
assembly codes/instructions.
• Decompiler is the utility program for translating machine codes into corresponding high level
language instructions.