Review of Instruction Formats, Program Build Process
Tom Kelliher, CS 240
Oct. 5, 2005
First exam on Oct. 12, covering: 2.1-2.10, 2.13, 2.15.
Collect assignment; next assignment.
Read 3.1-3.2.
Finished up function call mechanism.
- Summary of operand addressing.
- Program build process.
Number representation.
Register, immediate, base and offset, PC-relative, ``direct.''
Base and offset is a form of indirect addressing.
- Register mode. Format:
Example: add $t0, $t0, $t1
- Immediate mode. Format:
Examples:
addi $t0, $t0, 1
lw $t1, 4($t0)
- Suppose we need to branch further than
words?
- Example: procedure call in huge program.
- Solution: J format:
Example: j reallyFarLabel
- Conditional branch example:
<code>
while: beq $t0, $t1, reallyFarLabel
<lots of code>
b while
becomes:
<code>
while: bne $t0, $t1, near
j reallyFarLabel
near: <lots of code>
j while
- Why can't this take us anywhere in memory?
Solved with jr!
These are just comments. Make sure you read 2.10 on your own!
- Assembler output: object file --
- Data segment holds constants, generally strings and arrays.
Scalar constants will be embedded in the code.
Dynamic data is maintained in the heap segment.
- Relocation absolute addresses: J format and
jr style
instructions.
Program assembled assuming it will be load starting at address 0. This
is never the case.
- Symbol table's external references -- must be resolved by the
linker.
- Linker output: executable file --
- Think of source program split into multiple files -- one function
per file. These are compiled into object files.
Advantages?
- External references are resolved -- calls between object
files. Also, library code must be
added to the code segment and absolute addresses for library function
calls must be filled in within the original program.
Example: printf("The answer is: %d", ans);
- Static linking. Impact upon disk and memory footprints.
- Loader: load executable into memory and set execution environment.
- Dynamic linked libraries.
- Initial version: smaller disk footprint. Linked at load time, so
larger memory footprint, but library modules can be shared between
programs.
- Lazy linkage: smallest footprints. Don't link libraries until
they are actually needed. Requires indirection:
This is the mechanism Microsoft uses. DLL ``Hell.''
Thomas P. Kelliher
2005-10-05
Tom Kelliher