SlideShare uma empresa Scribd logo
1 de 6
Baixar para ler offline
Assemblers, Linkers & Loaders




C program
                                    Translation Hierarchy
        Compiler



            Assembly language program



                            Assembler



                    Object: Machine language module     Object: Library routine (machine language)



                                               Linker



                                          Executable: Machine language program



                                                                     Loader



                                                                              Memory




                                                                                                     1
Translation Hierarchy
• Compiler
  – Translates high-level language program into
    assembly language (CS 440)
• Assembler
  – Converts assembly language programs into
    object files
      • Object files contain a combination of machine
        instructions, data, and information needed to place
        instructions properly in memory




                   Assemblers
• Assemblers need to
   – translate assembly instructions and pseudo-instructions
     into machine instructions
   – Convert decimal numbers, etc. specified by
     programmer into binary
• Typically, assemblers make two passes over the
  assembly file
   – First pass: reads each line and records labels in a
     symbol table
   – Second pass: use info in symbol table to produce actual
     machine code for each line




                                                               2
Object file format
     Object file      Text       Data     Relocation     Symbol    Debugging
      header        segment    segment   information      table   information


  • Object file header describes the size and position of the
    other pieces of the file
  • Text segment contains the machine instructions
  • Data segment contains binary representation of data in
    assembly file
  • Relocation info identifies instructions and data that depend
    on absolute addresses
  • Symbol table associates addresses with external labels and
    lists unresolved references
  • Debugging info




             Process for producing an
                  executable file

Source                              Object
                   Assembler
 file                                file



Source                              Object                            Executable
                   Assembler                           Linker
 file                                file                                file



Source                              Object             Program
                   Assembler
 file                                file               library




                                                                                   3
Object file
                                           sub:
                                               ·
               Object file                     ·             Executable file
                                               ·
Instructions     main:                                        main:
                  jal ???                                      jal printf
                    ·                                            ·
                    ·                                            ·
                    ·                                            ·
                  jal ???                                      jal sub
                                                              printf:
                 call, sub                          Linker         ·
Relocation       call, printf                                      ·
records                                                            ·
                                                              sub:
                                                                   ·
                                C library                          ·
                                                                   ·
                                  print:
                                            ·
                                            ·
                                            ·




                                                Linker
   • Tool that merges the object files produced by
     separate compilation or assembly and creates an
     executable file
   • Three tasks
         – Searches the program to find library routines used by
           program, e.g. printf(), math routines,…
         – Determines the memory locations that code from each
           module will occupy and relocates its instructions by
           adjusting absolute references
         – Resolves references among files




                                                                               4
5
Loader
• Part of the OS that brings an executable file
  residing on disk into memory and starts it running
• Steps
   – Read executable file’ header to determine the size of
                           s
     text and data segments
   – Create a new address space for the program
   – Copies instructions and data into address space
   – Copies arguments passed to the program on the stack
   – Initializes the machine registers including the stack ptr
   – Jumps to a startup routine that copies the program’  s
     arguments from the stack to registers and calls the
     program’ main routine
               s




            $sp    7fff ffff       hex      Stack




                                         Dynamic data

            $gp    1000 8000              Static data
                                   hex

                   1000 0000       hex

                                             Text
            pc     0040 0000       hex
                                          Reserved
                               0




                                                                 6

Mais conteúdo relacionado

Mais procurados

Introduction to loaders
Introduction to loadersIntroduction to loaders
Introduction to loaders
Tech_MX
 
Overall 23 11_2007_hdp
Overall 23 11_2007_hdpOverall 23 11_2007_hdp
Overall 23 11_2007_hdp
Mohd Arif
 
Workshop Assembler
Workshop AssemblerWorkshop Assembler
Workshop Assembler
Tuhin_Das
 

Mais procurados (20)

Something About Dynamic Linking
Something About Dynamic LinkingSomething About Dynamic Linking
Something About Dynamic Linking
 
06 - ELF format, knowing your friend
06 - ELF format, knowing your friend06 - ELF format, knowing your friend
06 - ELF format, knowing your friend
 
Loaders ( system programming )
Loaders ( system programming ) Loaders ( system programming )
Loaders ( system programming )
 
Introduction to loaders
Introduction to loadersIntroduction to loaders
Introduction to loaders
 
loaders and linkers
 loaders and linkers loaders and linkers
loaders and linkers
 
Linker and loader upload
Linker and loader   uploadLinker and loader   upload
Linker and loader upload
 
Loaders
LoadersLoaders
Loaders
 
Loader
LoaderLoader
Loader
 
Single Pass Assembler
Single Pass AssemblerSingle Pass Assembler
Single Pass Assembler
 
ELF
ELFELF
ELF
 
Assembler
AssemblerAssembler
Assembler
 
Strategies to improve embedded Linux application performance beyond ordinary ...
Strategies to improve embedded Linux application performance beyond ordinary ...Strategies to improve embedded Linux application performance beyond ordinary ...
Strategies to improve embedded Linux application performance beyond ordinary ...
 
Overall 23 11_2007_hdp
Overall 23 11_2007_hdpOverall 23 11_2007_hdp
Overall 23 11_2007_hdp
 
Libraries
LibrariesLibraries
Libraries
 
Unit1 cd
Unit1 cdUnit1 cd
Unit1 cd
 
P code
P codeP code
P code
 
Compilation
CompilationCompilation
Compilation
 
Compiler unit 1
Compiler unit 1Compiler unit 1
Compiler unit 1
 
Design of a two pass assembler
Design of a two pass assemblerDesign of a two pass assembler
Design of a two pass assembler
 
Workshop Assembler
Workshop AssemblerWorkshop Assembler
Workshop Assembler
 

Destaque (6)

Linkers in compiler
Linkers in compilerLinkers in compiler
Linkers in compiler
 
Introduction to compiler construction
Introduction to compiler constructionIntroduction to compiler construction
Introduction to compiler construction
 
Linkers And Loaders
Linkers And LoadersLinkers And Loaders
Linkers And Loaders
 
Introduction to Compiler Construction
Introduction to Compiler Construction Introduction to Compiler Construction
Introduction to Compiler Construction
 
Linkers
LinkersLinkers
Linkers
 
Code generation
Code generationCode generation
Code generation
 

Semelhante a Assembler

Understanding how C program works
Understanding how C program worksUnderstanding how C program works
Understanding how C program works
MindBridgeTech
 

Semelhante a Assembler (20)

Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
Eusecwest
EusecwestEusecwest
Eusecwest
 
10 implementing subprograms
10 implementing subprograms10 implementing subprograms
10 implementing subprograms
 
Understanding how C program works
Understanding how C program worksUnderstanding how C program works
Understanding how C program works
 
Compiler Design Introduction
Compiler Design IntroductionCompiler Design Introduction
Compiler Design Introduction
 
Linkers
LinkersLinkers
Linkers
 
Part I_Translating & Starting a Program_Compiler, Linker, Assembler, Loader_L...
Part I_Translating & Starting a Program_Compiler, Linker, Assembler, Loader_L...Part I_Translating & Starting a Program_Compiler, Linker, Assembler, Loader_L...
Part I_Translating & Starting a Program_Compiler, Linker, Assembler, Loader_L...
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
Dynamic Languages in Production: Progress and Open Challenges
Dynamic Languages in Production: Progress and Open ChallengesDynamic Languages in Production: Progress and Open Challenges
Dynamic Languages in Production: Progress and Open Challenges
 
Compiler1
Compiler1Compiler1
Compiler1
 
Robocopy
RobocopyRobocopy
Robocopy
 
Advanced c programming in Linux
Advanced c programming in Linux Advanced c programming in Linux
Advanced c programming in Linux
 
.NET Core, ASP.NET Core Course, Session 3
.NET Core, ASP.NET Core Course, Session 3.NET Core, ASP.NET Core Course, Session 3
.NET Core, ASP.NET Core Course, Session 3
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
 
OpenCascade Technology Overview: OCAF
OpenCascade Technology Overview: OCAFOpenCascade Technology Overview: OCAF
OpenCascade Technology Overview: OCAF
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
 
Compier Design_Unit I.ppt
Compier Design_Unit I.pptCompier Design_Unit I.ppt
Compier Design_Unit I.ppt
 
Compier Design_Unit I.ppt
Compier Design_Unit I.pptCompier Design_Unit I.ppt
Compier Design_Unit I.ppt
 
Chapter 1.pptx
Chapter 1.pptxChapter 1.pptx
Chapter 1.pptx
 
The Scheme Language -- Using it on the iPhone
The Scheme Language -- Using it on the iPhoneThe Scheme Language -- Using it on the iPhone
The Scheme Language -- Using it on the iPhone
 

Último

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Último (20)

Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 

Assembler

  • 1. Assemblers, Linkers & Loaders C program Translation Hierarchy Compiler Assembly language program Assembler Object: Machine language module Object: Library routine (machine language) Linker Executable: Machine language program Loader Memory 1
  • 2. Translation Hierarchy • Compiler – Translates high-level language program into assembly language (CS 440) • Assembler – Converts assembly language programs into object files • Object files contain a combination of machine instructions, data, and information needed to place instructions properly in memory Assemblers • Assemblers need to – translate assembly instructions and pseudo-instructions into machine instructions – Convert decimal numbers, etc. specified by programmer into binary • Typically, assemblers make two passes over the assembly file – First pass: reads each line and records labels in a symbol table – Second pass: use info in symbol table to produce actual machine code for each line 2
  • 3. Object file format Object file Text Data Relocation Symbol Debugging header segment segment information table information • Object file header describes the size and position of the other pieces of the file • Text segment contains the machine instructions • Data segment contains binary representation of data in assembly file • Relocation info identifies instructions and data that depend on absolute addresses • Symbol table associates addresses with external labels and lists unresolved references • Debugging info Process for producing an executable file Source Object Assembler file file Source Object Executable Assembler Linker file file file Source Object Program Assembler file file library 3
  • 4. Object file sub: · Object file · Executable file · Instructions main: main: jal ??? jal printf · · · · · · jal ??? jal sub printf: call, sub Linker · Relocation call, printf · records · sub: · C library · · print: · · · Linker • Tool that merges the object files produced by separate compilation or assembly and creates an executable file • Three tasks – Searches the program to find library routines used by program, e.g. printf(), math routines,… – Determines the memory locations that code from each module will occupy and relocates its instructions by adjusting absolute references – Resolves references among files 4
  • 5. 5
  • 6. Loader • Part of the OS that brings an executable file residing on disk into memory and starts it running • Steps – Read executable file’ header to determine the size of s text and data segments – Create a new address space for the program – Copies instructions and data into address space – Copies arguments passed to the program on the stack – Initializes the machine registers including the stack ptr – Jumps to a startup routine that copies the program’ s arguments from the stack to registers and calls the program’ main routine s $sp 7fff ffff hex Stack Dynamic data $gp 1000 8000 Static data hex 1000 0000 hex Text pc 0040 0000 hex Reserved 0 6