1.3 Cousins of The Compiler
1.3 Cousins of The Compiler
1.3 Cousins of The Compiler
Compiler
Context of the Compiler
• Several other programs are required to create
executable target programs
PREPROCESSOR
Source Program
COMPILER
ASSEMBLER
• 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