Tutorials - Loader
Compile several programs in SIC/XE assembly (from previous exercises). Look at the generated obj files.
- Which records they contain?
- What is the start (origin) address for loading the program?
- Where (to which address) is the code loaded to?
- What is the start address for execution?
Loader in Java
For loading obj files we need methods for reading a string, one, byte and one word. We can write them (as static methods) in some helper class, e.g., Utils. You may opt to use Java Reader class for reading, so you can reuse the methods to read from strings, files, etc.
Write the following methods:
- String readString(Reader r, int len)
- int readByte(Reader r)
- int readWord(Reader r)
Loading a section
An obj file actually represent a control section (you will learn about this at lectures). Write a method (e.g. in the class Machine) for loading it. We need a method such as
- boolean loadSection(Reader r)
This method should load an object code into the memory.
Write an absolute loader, i.e., the code is loaded directly to the address specified in the object file. After loading you should also set the PC register to the corresponding value.
*Loader in SIC/XE assembly
See an an example loader in SIC/XE assembly.
- Where is the code loaded? To which address?
- From which device it loades the code?
- What is the format of the code?
Download the file F1.dev, which contains some program. The above loader can load this file and execute it. Try it!
- Which program does it contain?
Try the same thing with one of your programs. Hints:
- You may start with the obj file, which you transform to be compatible with the above loader.
- Be careful with RESB in RESW directives, which does not generate T records, but you should instead generate a corresponding number of zeros.
Have fun and good luck.