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

Compiler Construction: Submitted To: Uzair Sahib

Uploaded by

maharashfaq056
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views15 pages

Compiler Construction: Submitted To: Uzair Sahib

Uploaded by

maharashfaq056
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

COMPILER

CONSTRUCTION

Submitted to: Uzair


Sahib
Submitted By:

 Mahar M Ashfaq
 Malik M Imran
 Ch M Husnain
 Ch M Hamza Sajjad
 M Huzaifa Mustafa Hanjra
ADDRESSES IN TARGET
CODE

Made By Mahar M Ashfaq


Addresses in Target Code
 What is Target Code?
 Target code refers to the machine-level code
(or binary code) generated after compiling a
program's source code.

 Why are Addresses Important?


 In target code, addresses are used to locate
variables, functions, and other data in
memory.
What is an Address

 An address is a unique identifier for a


location in memory.
 It tells the CPU where to fetch or store
data during program execution.
Types of Addresses:

 Logical/Virtual Addresses: These are


the addresses used by the program.

 Physical Addresses: These correspond


to actual locations in the computer's
hardware memory.
How Addresses are Assigned
in Target Code
 Code Segment: Contains the executable
instructions.
 Start Address: The first instruction’s address
in memory.
 Offset: The position of an instruction relative
to the start of the code segment.

 Data Segment: Contains global and


static variables.
How Addresses are Assigned in
Target Code

 Stack: Used for function calls, local


variables, and return addresses.

 Heap: Used for dynamic memory


allocation (e.g., malloc in C).
Relocation and Address
Translation

 Relocation:
 During the compilation process, code is often
not linked to a specific memory address.
Relocation is the process of adjusting
addresses when a program is loaded into
memory.
Relocation and Address
Translation

 Linking:
 When programs are compiled, external
references are often left as placeholders.
These are resolved at the linking stage to form
the final target code with specific addresses.
Example of Target Code
Addresses
 _start:
 mov eax, 10 ; address of "eax" in the
register file
 add eax, 5 ; address of next
instruction in the
code segment
 ret ; address of the return
instruction in
memory
Addressing Modes
 Direct Addressing: The instruction
contains the address of the operand.

 Indirect Addressing: The instruction


contains a pointer to the address.

 Indexed Addressing: An address is


calculated by adding an index value to a
base address.
Importance of Understanding
Target Code Addresses

 Debugging:Knowing memory addresses


helps in debugging, especially when
tracking down errors like segmentation
faults.

 Optimization:Optimizing code often


involves minimizing memory usage,
which requires understanding how
memory is allocated and addressed.
Importance of Understanding
Target Code Addresses

 Security:Understanding memory layout


can help identify vulnerabilities, such as
buffer overflows.
Thank You

You might also like