Pass 1 of a Linking Loader is responsible for preparing and analyzing object modules before loading and linking. In this pass, the loader performs several important tasks:
Memory Allocation: The loader determines the memory space required for each module and allocates it accordingly. It establishes where code and data will reside in memory.
Symbol Table Creation: All symbols (such as variables and functions) used across modules are identified and stored in a symbol table. This table tracks each symbol's location and attributes.
External References Resolution: External symbols (those used in one module but defined in another) are flagged for resolution in Pass 2. These references cannot be fully processed until the modules are linked.
Relocation Information: The loader generates relocation details, specifying where addresses need adjustment. This ensures that after loading, all memory references are valid.
Pass 1 prepares all modules for the actual linking, relocation, and final execution in Pass 2.
Begin
get PROOADDR from operating system
set CSADDR to PROOADDR {for first control section}
while not end of input do
begin
read next input record {Header record for control section}
set CSLTH to control section length
search ESTAB for control section name
if found then
set error flag {duplicate external symbol}
else
enter control section name into ESTAB with value CSADDR
while record type ~ 'E' do
begin
read next input record
if record type = 'D' then
for each symbol in the record do
begin
search ESTAB for symbol name
if found then
set error flag (duplicate external symbol)
else
enter symbol into ESTAB with value(CSADDR + indicated address)
end {for}
end {while ~ 'E'}
add CSLTH to CSADDR {starting address for next control section}
end {while not EOF}
end {Pass 1}
Input file:
Input.txt
H PROGA 000000 000063
D LISTA 000054
R LISTB ENDB LISTC ENDC
T 000020 0A 03201D 77100004 050014
T 000054 0F 100014 000008 004051 000004 100000
M 000024 05 +LISTB
M 000054 06 +LISTC
M 000060 06 +LISTB
M 000060 06 -LISTA
E 000020
H PROGB 000000 00007F
D LISTB 000060 ENDB 000070
R LISTA LISTC ENDY
T 000036 0B 03100000 772027 05100000
T 000070 0F 100000 000008 004051 000004 100060
M 000037 05 +LISTA
M 00003E 05 -LISTA
M 000070 06 -LISTA
M 000070 06 +LISTC
M 00007C 06 +PROGB
M 00007C 06 -LISTA
E 000000
H PROGC 000000 0000051
D LISTC 000030 ENDC 000042
R LISTA LISTB ENDB
T 000018 0C 03100000 77100004 05100000
T 000042 0F 100030 000008 004051 000004 100000
M 00001D 05 +LISTB
M 000021 05 -LISTA
M 000042 06 -LISTA
M 000042 06 +PROGC
M 00004E 06 +LISTB
M 00004E 06 -LISTA
E
END
starting adresss is 4000
output file:
estab.txt
PROGA ** 4000 63
** LISTA 4054
PROGB ** 4063 7f
** LISTB 40c3
** ENDB 40d3
PROGC ** 40e2 51
** LISTC 4112
** ENDC 4124