1.3 Cousins of The Compiler

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 10

Cousins of the

Compiler
Context of the Compiler
• Several other programs are required to create
executable target programs

PREPROCESSOR

Source Program

COMPILER

Target Assembly program

ASSEMBLER

Relocatable machine code

LOADER / LINK EDITOR Absolute machine code


Preprocessors
• Collect Source program segments and also
expands macros
• Produce input to compilers
– Macro processing
– File inclusion – includes header files
– Rational preprocessors
• Augment older languages
– Language Extensions
• Adds capabilities to the language
• Database access statements
Preprocessors
• Macro definition
– Indicated by define
– Name of macro and body – definition
– Formal parameters
• Macro Usage
– Name and actual parameters
Preprocessors

• In TEX:
\define <macro name> <template> { <body>}
\define \JACM #1;#2;#3 {{\sl J.ACM}{\bf
#1}:#2,pp.#3.}
\JACM 17;4; 715-728
J.ACM 17:4, pp.715-728.
Assemblers
• Compilers may produce assembly code or re
locatable machine code
• Assembly code uses mnemonics for opcodes and
names for addresses
• Example: Computes b = a+2

MOV a, R1
ADD #2, R1
MOV R1, b
Two pass Assembly
• Makes 2 passes
• First pass all identifiers denoting storage
locations are found and stored in symbol
table; addresses are also assigned
IDENTIFIER ADDRESS
a 0
b 4
Two pass Assembly
• Second pass – scans input and translates
operation code into bits
• Output: Relocatable machine code
– Can be loaded in any location
– Load (0001) / Store (0010) / Add (0011)
– Register
– Tag (00 – Ordinary address mode / 10 – Immediate mode)
– * - Relocation bit

0001 01 00 00000000 *
0011 01 10 00000010
0010 01 00 00000100 *
Loaders
• Input: relocatable machine code
– Alters addresses
– Places into memory
Link Editors

• Creates a single program from several files


of re locatable machine code and library
routines
• External References
– External Symbol Directory

You might also like