Changelog:

These is documentation for the object file and executable file format to be used int he linking task

Object file format

Each file has 3 parts, separated by “***”:

  1. Machine code/data. Each file’s machine code is written in hexadecimal as a sequence of bytes, each byte written with two hexadecimal “nibbles” (even if its value is less than 16). The bytes are space-seperated in our examples, but this is not required. Each line of hexadecimal is prefixed with starting offset in hexadecimal followed by a “:”. Relocations to be filled in are represented with 0 bytes. Omitted bytes are assumed to be zeroes.

  2. A list of relocations. Each relocation is comma separated line containing:

    • the offset (as a hexadecimal number) of the relocation to be filled in, and
    • the symbol to fill in
  3. A list of symbols Each symbol is comma separated line containing:

    • the offset (as a hexadecimal number) of the symbol, and
    • the symbol to fill in

Example:

      0x0: 11 22 33 44
0x4: 55 66 77 88
0x8: 99 AA BB CC
0xC: 00 00 00 00
0x10: 00 00 00 00
***
0xC,foo
***
0x0,start

    

specifies an object file containing 20 bytes of machine code and/or data, with a ‘start’ symbol at offset 0x0 and a relocation (whose corresponding machine code/data bytes happen to all be 0s before the replacement, though this is not required) to be replaced with the address of ‘foo’ at offset 0xC.

The above example could also be written with less whitespace and more bytes per line, like:

      0x00: 1122334455667788
0x08: 99AABBCC00000000
0x10: 00000000
***
0x0C,foo
***
0x00,start

    

Executable file format:

Executable files (for the homework only) consist of lines of hexadecimal byte values prefixed with with the address to which they should be loaded in hexadecimal followed by a “:”. For example:

      0x0: 11 22 33 44
0x4: 55 66 77 88
0x8: 99 AA BB CC
0xC: EE FF 00 11

    

specifies an executable that would load 16-bytes into memory starting at address 0x0.

The whitespace between the hexadecimal for each byte can be omitted, and more than four bytes can be placed per line.

This is essentially the same as the format that tools/yas produces.

Like in the code we use for HCLRS, executables should arrange for the address of main to be at 0x0, and then include the data machine/code from the other object files used to construct them in any order.