Assembler

The assembler's job is to take programs written in the PASM assembly language and translate them to one of three formats:

Usage

The assembler executable can be invoked with various flags. To see an exhaustive list of the same, invoke it with the --help flag. The output will be something like this:

λ⟩ assembler --help
Usage: assembler [options] <file_path>.
  --format 
        Output format (bin | inter | ascii)
  -fmt 
        Short for --format
  --out 
        Output file path
  -o 
        Short for --out
  --help 
        Display this list of options
  -help 
        Display this list of options
  -h 
        Short for --help / -help

Example

The examples/ directory in the source code contains a PASM program to place the first n Fibonacci numbers in the memory, starting at address k, where the initial value of RAM[0] contains n, and that of RAM[1] contains k.

# fib.pasm

# Let RAM[0] store n and RAM[1] store k.
# This program computes the first n Fibonacci numbers and puts them
# in RAM, starting at address k.


ld r1 r0 0
ld r2 r0 1

addi r3 r0 0
addi r5 r0 0
addi r6 r0 1

loop:
	beq r3 r1 halt
 	add r4 r2 r3
 	st 	r5 r4 0
 	add r6 r6 r5
 	sub r5 r6 r5
 	addi r3 r3 1
 	j loop
 
halt:
	j halt

To assemble this and see the ASCII representation of the PISA binary, the assembler executable can be invoked as follows:

λ⟩ assembler fib.pasm -fmt=ascii -o fib-ascii
Wrote: fib-ascii

λ⟩ cat fib-ascii
0010000100000000
0010001000000001
0101001100000000
0101010100000000
0101011000000001
1001001100010111
0100010000100011
0011010101000000
0100011001100101
0110010101100101
0101001100110001
1101111111111010
1101000000000000

Source code and documentation

The source code for the assembler can be found on our GitLab repository, in the assembler directory.

The odoc generated documentation for the libraries involved can be read here: