To eventually run (execute) a program, the following things are done:
We have talked about steps 1 and 2.
Assembly just produces enough information about what goes where in memory to make the code run. It does not actually put the stuff in memory. Linking and loading puts all the stuff into memory at the right places.
What goes into memory?
Where are the correct locations?
Answer: Exactly where the assembler assigns them.
The data section starts at 0x00400000 in our simulator of the MIPS RISC processor.
So, if we had source code with,
.data a1: .word 15 a2. .word -2
then the assembler needs to specify that memory will need to be initially set up with
address contents 0x00400000 0000 0000 0000 0000 0000 0000 0000 1111 0x00400004 1111 1111 1111 1111 1111 1111 1111 1110
Like the data, the code needs to be placed starting at a specific location to make it work.
Consider the case where the assembly language code is split across 2 files. Each is assembled separately.
in file 1:
.data a1: .word 15 a2: .word -2 .text __start: la $t0, a1 add $t1, $t0, $s3 jal proc5 done
in file 2:
.data a3: .word 0 .text proc5: lw $t6, a1 sub $t2, $t0, $s4 jr $ra
Two problems with this:
a1(in file1) is supposed to be placed at 0x00400000
a3(in file2) is supposed to be placed at 0x00400000
__start(in file1) is placed at location 0x00800000
proc5(in file2) is placed at location 0x00800000
proc5is never defined (given an address). That is because the label (symbol) is defined in file 2. The address assigned to
proc5is needed to produce the machine code for the
jalinstruction in file 1.
This same problem presents itself in the
in file 2. The address assigned to
a1 is unknown when
assembling file 2. This is because the symbol
a1 is defined
(and given an address) in file 1.
The real problem here is that absolute addresses are needed to produce the machine code.
A single program (all code and data) MUST be all in one file.
Why is this bad?
To accomodate linking and loading, the information produced by the assembler must include:
This last one is something new.
Have the assembler
|Copyright © Karen Miller, 2006|