Download presentation
Presentation is loading. Please wait.
Published byCarmella Bell Modified over 8 years ago
1
5-1 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Principles of Computer Architecture Miles Murdocca and Vincent Heuring Chapter 5: Languages and the Machine
2
5-2 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Topics 5.2 The Assembly Process 5.3 Linking and Loading 5.4 Macros Linker exe file Prog1 (MC) prog2 (MC) prog n (MC) … LoaderMemory Assembler Assembly lan. progsMachine code libs
3
5-3 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring The Assembly Process The process of translating an assembly language program into a machine language program is referred to as the assembly process. Assemblers generally provide this support: — Allow programmer to specify locations of data and code. — Provide assembly-language mnemonics for all machine instructions and addressing modes, and translate valid assembly language statements into the equivalent machine language. — Permit symbolic labels to represent addresses and constants. — Provide a means for the programmer to specify the starting address of the program, if there is one; and provide a degree of assemble-time arithmetic. — Include a mechanism that allows variables to be defined in one assembly language program and used in another, separately assembled program. — Support macro expansion.
4
5-4 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Assembly Example We explore how the assembly process proceeds by “hand assembling” a simple ARC assembly language program.
5
5-5 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Macro Definition for PUSH
6
5-6 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Macro expansion for PUSH PUSH %r2 PUSH %r3 PUSH %r1 MACRO definition …
7
5-7 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Instruc- tion For- mats and PSR Format for the ARC
8
5-8 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Assembled Code ld [x], %r1 1100 0010 0000 0000 0010 1000 0001 0100 ld [y], %r2 1100 0100 0000 0000 0010 1000 0001 1000 addcc %r1,%r2,%r3 1000 0110 1000 0000 0100 0000 0000 0010 st %r3, [z] 1100 0110 0010 0000 0010 1000 0001 1100 jmpl %r15+4, %r0 1000 0001 1100 0011 1110 0000 0000 0100 15 0000 0000 0000 0000 0000 0000 0000 1111 9 0000 0000 0000 0000 0000 0000 0000 1001 0 0000 0000 0000 0000 0000 0000 0000 0000
9
5-9 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring 2-PASS Assembler Goes over the program twice 1 st pass: Find out addresses for all DATA items and machine instructions Employing location counter and forward referencing Keep track of the addresses of the current instruction or data items as assembly proceeds Create a symbolic table Translate each assembly instruction into machine instruction Mnemonics Addressing modes Has not generated machine code yet. Location counter (similar to PC) Initialized to what.org specifies/zero Incremented by the size of each instruction
10
5-10 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Address for each instruction 2048 2052 2056 2060 2064 2068 2072 2076
11
5-11 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Symbol table Contains all labels and constant values in the assembly program After the first pass, the assembly will have identified and entered all symbols into the symbolic table during the second pass, the assembler generates the machine code, inserting the values of symbols, which are known
12
5-12 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Symbol table Symbol table for example 1: main2048 x2068 y2072 z2076
13
5-13 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring
14
5-14 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Symbol table Symbol value a_start3000 length -- address -- loop2060 done2088
15
5-15 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Symbol table cont’d Symbol value a_start3000 length 2092 (1) address 2096 (2) loop2060 done2088
16
5-16 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Assembled Program
17
5-17 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Second pass After the symbol table is created the program is read a second time Start from.begin Machine code is generated using symbol table
18
5-18 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Final tasks of the assembler Extra info to be added to the program for the linker and loader Linker: linking modules together Loader: putting the program into memory Module name and size Memory and segment info, such as code, data, stack The address of start symbol (if defined) The info about global and external symbols The address of any global symbols Info about any library routines that are referenced by the module The value of any constants to be loaded to memory Some loaders expect data initialization to be specified separately from the binary code Relocation info
19
5-19 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Relocation info Linker will link all the modules by concatenating them To do so some of the modules need to be relocated Example:
20
5-20 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Location of programs in memory As long as program is in user-accessible segment Might not in the address indicated by.org Modules are concatenated one after the other After linking, some modules are relocated to other addresses Most of addresses we use are re-locatable Exception: fixed addresses (I/O devices)
21
5-21 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring
22
5-22 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Linking and loading A number of separately compiled/assembled modules Linker: a software program Combines separately assembled programs (object modules) into a single program (load module/exe) Loader: a software program that places the load module into main memory Load the various memory segments with the appropriate values and initialize certain registers (i.e. %sp, %pc)
23
5-23 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring linking Resolve address refs that are external to modules as it links them Relocate each module in order to combine them Specify the starting symbol of the load module Identify different memory segments Needs to know local symbol names from global symbol names Only address labels can be global or external Some addresses can not be relocated External symbols defined in another module Absolute numbers (defined by pseudo-code) ONE.equ1 a_start.equ 3000 Content of the address when relocated, do not change i.e : x :105 !relocate x, address changes, but content remains the same
24
5-24 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Linking: Using.global and.extern A.global is used in the module where a symbol is defined and a.extern is used in every other module that refers to it.
25
5-25 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Linking and Loading: Symbol Tables Symbol tables for the previous example:
26
5-26 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring loading Relocating loader More than one modules, relocate by adding an offset to all re- locatable code in that module Linking loader Does both linking and loading header info An exe file contains a header (inserted by linker) Where to load the program Starting address Relocation info What routines are available externally Dll (microsoft)
27
5-27 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Example ARC Program
28
5-28 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Recursive Macro Expansion
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.