The final assignment of the 'System programming' course in the Open University.
This project is based on the two-pass assembler model.
Note: the computer model for this project and the given assembly language are imaginary.
The project was targeted to comply the C90 standard
and meant to be run on Linux env.
Use makefile to compile the project (and clean trailing object files) as follows:
> make
> make clean
After preparing assembly files with an .as
extension, open terminal and pass file names as arguments (without the file extensions) as following:
As for the files x.as, y.as, hello.as we will run:
> assembler x y hello
The assembler will generate output files with the same filenames and the following extensions:
.ob
- Object file.ent
- Entries file.ext
- Externals file.as
- Pre-assembled file (after macro expansion).
An example of input and output files can be found under the 'tests' folder.
- CPU
- RAM (including a stack), with the size of 256 words.
- A word's size in memory is 14 bits.
- Uses signed 2's complement arithmetic for integers (with no support for real numbers).
The CPU has 9 registers: 8 general registers (named r1,r2,...,r8).
Every software instruction is encoded into a few words in memory (max is 4 words). The first word is of the following structure:
13 12 | 11 10 | 9 8 7 6 | 5 4 | 3 2 | 1 0 |
---|---|---|---|---|---|
Param 1 | Param 2 | Opcode | Source operand | Dest operand | E.R.A |
Thanks for Chat gpt for generating this table
Encoding of each instruction word is done using the following format:
0: .
1: /
each word can be represented as 2 bytes, where we only use 8 bits from the first byte, and 6 bits from the second.
The commands allowed in bits 6-9 are:
Opcode (decimal) | Command Name |
---|---|
0 | mov |
1 | cmp |
2 | add |
3 | sub |
4 | not |
5 | clr |
6 | lea |
7 | inc |
8 | dec |
9 | jmp |
10 | bne |
11 | red |
12 | prn |
13 | jsr |
14 | rts |
15 | stop |
A directive line of the following structure:
-
An optional preceding label. e.g.
PLACE1:
. -
A directive:
.data
,.string
,.entry
or.extern
. -
Operands according to the type of the directive.
This directive allocates memory in the data image for storing received integers later in memory (also increases the data counter and updates the symbol table). The parameters of
.data
are valid integers (separated by a comma).
e.g.LABEL1: .data +7, -56, 4, 9
.This direcive receives a string as an operand and stores it in the data image. It stores all characters by their order in the string, encoded ny their ASCII values. e.g.
STRING1: .string "abcdef"
is a valid directive.This directive outputs a received name of a label to the symbol table, so that later it will be recognized by other assembly files (and they would be able to use it). e.g.
; file1.as .entry HELLO HELLO: add #1, r1
This directive receives a name of a label as a parameter and declares the label as being external (defined in another file) and that the current file shall use it.
This way, the directive.extern HELLO
infile2.as
will match the.entry
directive in the previous example.