S2.20.1 Link Two Files

EasyImplement12 minIcarus Verilog · serverReview the topic

Do the work of a linker by hand for two object files: place four sections, find four symbols and fill one hole.

Hardware context: Two object files held as arrays (six instruction words with two holes, and two data words), with a small linker and loader as test code. Building the software image of a chip, and reading a linker map

A linker joins two object files, a.o and b.o. It places the code of a.o at address 0, and the code of b.o directly after it. It places the data of a.o at address 128, and the data of b.o directly after that. All addresses and sizes here are in decimal, in bytes.

This worksheet uses named constants. The first three entries show how to record your decisions.

Signals in the Timeline

SignalWidthRole
question8input of each check
Full specification
The two object files
The code of a.o has one hole: the jal at code + 8 calls helper.
FileCode sectionData sectionSymbols it defines
a.o24 bytes8 bytesmain at code + 0; total at data + 4
b.o16 bytes12 byteshelper at code + 4; table at data + 0

Enter every value in decimal. For a yes or no question, enter 1 for yes and 0 for no.

EntryYour decision
CODE_BASE_OF_BAt which address does the code of b.o start?
ADDRESS_OF_MAINWhat is the address of main?
ADDRESS_OF_HELPERWhat is the address of helper?
END_OF_CODEWhat is the first address after all the code?
DATA_BASE_OF_BAt which address does the data of b.o start?
ADDRESS_OF_TOTALWhat is the address of total?
ADDRESS_OF_TABLEWhat is the address of table?
END_OF_DATAWhat is the first address after all the data?
ADDRESS_OF_THE_JALAt which address is the jal that calls helper?
OFFSET_IN_THE_JALWhich offset does the linker write into that jal?
RA_AFTER_THE_JALWhat does ra hold after that jal has run?
ASSEMBLER_KNOWS_HELPERDoes the assembler know the address of helper when it works on a.o?
LINK_WITHOUT_BDoes the link succeed if b.o is left out?
HELPER_FOR_A_CODEThe code of a.o becomes A_CODE bytes long. Give the address of helper, as an expression in A_CODE.

Examples

Example 1

CODE BASE OF B
Input
At which address does the code of b.o start?
Output
matches = 1

Directly after the 24 bytes of code of a.o.

Example 2

ADDRESS OF MAIN
Input
What is the address of main?
Output
matches = 1

The base of the code of a.o, 0, plus the offset 0.

Example 3

ADDRESS OF HELPER
Input
What is the address of helper?
Output
matches = 1

The base of the code of b.o, 24, plus the offset 4.

Constraints and Contract

  • Keep the parameter and named constants. Use the numeric codes and units on this page.
  • For HELPER_FOR_A_CODE, enter a constant expression using A_CODE. Only this entry changes with the parameter. The supported integer range is 24 through 200, inclusive.

Hints

Hint 1

Write down the first and the last address of each of the four sections.

Hint 2

For each symbol, add its offset to the base of its section.

Hint 3

For the jal, subtract the address of the jal from the address of its target.

What the grader checks: Each check compares the full eight-bit answer. Parameter trials change one condition and keep the other decisions fixed.

14 checks on Icarus Verilog · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain your source only; samples require the simulation service. A passing result establishes the tested cases, not a proof for all possible inputs.

See all 1 problem on this path

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

CODE BASE OF B

Input
At which address does the code of b.o start?
Expected output
matches = 1

Directly after the 24 bytes of code of a.o.

Run samples executes all 3 public checks. Check all tests runs 14 checks on the server.

Icarus Verilog · server