0% found this document useful (0 votes)
6 views

Code to Microprocessor (1)

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Code to Microprocessor (1)

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Code To

microprocesso
How it process?
r
@nitinsxng
h
1: Source Code: High-level code
written by the developer.
The high-level, human-readable code
written by a developer in a programming
language (e.g., C, Python, Java). It uses
natural language-like syntax and
abstractions, making it easier to
understand, develop, and maintain. This
is the starting point of the compilation or
interpretation process.
@nitinsxng
h
2: Preprocessed Code: Handle
#include. Expands the header file.
The output of the preprocessing phase
in compilation, where directives like
#include, #define, and macros are
expanded. This step replaces header
files and macros with their actual
content, preparing the code for the
compilation phase.
@nitinsxng
h
Example:
int, main, (, ), {, int, x, =, 3, ,, y, =, 4, ;, int, z, =, x, *,
y, ;, printf, (, "Product: %d\n", z, ), ;, return, 0, ;, }

3: Lexical Analysis: Break code into


tokens.
The process of scanning source code
and breaking it into small, meaningful
units called tokens, such as keywords,
identifiers, operators, literals, and
punctuation. Tokens are the building
blocks for further stages of compilation.
@nitinsxng
h
4: Syntax Tree: Build a syntax tree
(AST)
A hierarchical tree representation of the
structure of source code, showing the
relationships between syntax elements
like functions, variables, operators, and
statements according to the grammar of
the programming language.
@nitinsxng
h
5: Annotated AST / Semantic
Analysis: Validate types and logical
correctness.

The process of adding type and scope


information to the Abstract Syntax Tree
(AST) to validate the program's
correctness. It ensures proper type
usage, checks variable declarations,
function calls, and resolves identifiers,
confirming the program
@nitinsxng adheres to
h
6: IR: Intermediate Code
Generation: Convert to platform-
independent representation.
The process of transforming the
annotated Abstract Syntax Tree (AST)
into a lower-level, platform-
independent representation. This IR
serves as a bridge between the high-
level source code and target machine
code, capturing the program's logic in
a simplified and standardized form,
such as three-address code or static
single assignment (SSA).
@nitinsxng
h
7: Assembly Code (x86-64): Code
Generation, Convert optimized IR
into assembly.
The process of converting the
optimized Intermediate Representation
(IR) into platform-specific assembly
language instructions (e.g., x86-64).
This step maps high-level operations to
machine-level instructions specific to
the target processor architecture,
considering registers, memory access,
and instruction sets.

@nitinsxng
h
8: final binary file in hexadecimal:
7F 45 4C 46 02 01 01 00 ... ; ELF
Header
B8 03 00 00 00 ; mov eax, 3
BB 04 00 00 00 ; mov ebx, 4
0F AF C3 ; imul eax, ebx
50 ; push eax
68 00 01 40 00 ; push msg address
E8 xx xx xx xx ; call printf
83 C4 08 ; add esp, 8
31 C0 ; xor eax, eax
C3 ; ret
50 72 6F 64 75 63 74 3A ... ; "Product:
%d\0” @nitinsxng
h
9: Hexadecimal Breakdown and
Conversion to Binary

ELF Header
7F 45 4C 46 02 01 01 00 ...

This is the ELF header. Let's convert


each of these hexadecimal values to
binary:
7F → 01111111
45 → 01000101
4C → 01001100
46 → 01000110
02 → 00000010
01 → 00000001
01 → 00000001
00 → 00000000... @nitinsxng
h
10: Binary code (machine code) is
the set of 0s and 1s that
represents instructions for the
microprocessor. The processor
fetches, decodes, and executes
these binary instructions

01010000 01110010 01101111


01100100 01110101 01100011
01110100 00111010 00100000
00100101 01100100 00001010
00000000... @nitinsxng
h

You might also like