System Software Lab - An Introduction to the Absolute Loader
So our first hurdle is to attempt to make an absolute loader. So what is an absolute loader? What is a loader?
A loader is simply a piece of software which is used to load the assembled object program into the computer's main memory (RAM) so that it can be executed. There are a ton of different loaders which do different things, but for now let's focus on the absolute loader.
The absolute loader loads the program into the exact memory locations that are specified in the program. So the programmer has specified locations for the code to be loaded and the loader places everything in RAM exactly where the programmer wanted it to be.
To understand better, let's look at some object code.
Object Code
Object code comprises of three parts, the header record, text record and end record.
The header record looks something like thisHCOPY 00100000107A
The first letter H indicates that its a header record. The next 6 positions (Each position is a hex digit. So each position occupies 4 bits. So the 6 positions will take 24 bits of space aka 3 bytes.) gives the name of the program. The next 3 bytes (6 positions) gives us the starting address of the program, i.e. to which address in RAM it should be loaded to by the absolute loader). The last 3 bytes specifies the length of the program.
The text record looks something like thisT00100004ABCDEF01
The first letter T indicates that its a text record. The next 3 bytes (6 positions) gives the address in RAM to which the object code in this text record is to be loaded. The next byte (2 positions) gives the length of the object code in this text record. The following bytes are the actual object code that is to be loaded. Here the length of this text record is specified as 04. This means that there are 4 bytes (8 positions) of object code in this text record.
The end record looks something like this
E001000
The first letter E indicates that its an end record. The 3 bytes after that is the starting address of the program so that the processor can begin execution after loading.
Typically the object code comprises of a single header record, followed by multiple text records, and end with a single end record. Now that we have an idea of what the object code looks like, lets see how the loader does its job.
Consider the following object code :HSUM 002000000010 T0020040534AA03EF42 T002009068693A73E1F99 E002000
The code should be loaded as shown,2000 xx 2001 xx 2002 xx 2003 xx 2004 34 2005 AA 2006 03 2007 EF 2008 42 2009 86 200A 93 200B A7 200C 3E 200D 1F 200E 99
Here the header record specifies that the program should start being loaded at location 2000. The first text record specifies that its object code should be loaded from location 2004 onwards. So the loader skips over till it reaches 2004 and it loads the object code from there. The next text record starts at 2009. So the loader loads its contents from 2009. Once that's done loading, it sees the end record. Now that loading is complete, the processor executes the program from the address given in the end record.
Hopefully with this short post, you've gotten an idea of how the absolute loader works and what it should do. If some areas are unclear, try reading it again and if it's still unclear, just ask and I'll try to rephrase it. I would recommend looking through this pdf also.
This was one of the articles written during my college days. You can find the original published article here