The assembler's job is to take programs written in the PASM assembly language and translate them to one of three formats:
inter: Intermediate PASM programs, with all the labels resolved and only the base PISA instructions (no pseudo-instructions).ascii: ASCII representations of PISA binaries, where each instruction is written in it's own line with 16-character strings consisting of 0s and 1s, corresponding to the bit-wise layout of the instruction.bin: PISA binaries.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 / -helpThe 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
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:
Assembler.Types: OCaml types for PASM and PISA instructions and programs. The extraction script maps types in the Rocq theories to these types.Assembler.Printers: Pretty printing functions for the types in Assembler.Types.Assembler.Parse: Functions to parse strings to PASM and PISA ASTs. These functions are wrappers over those generated by ocamllex and Menhir.Assembler.Assemble: Functions to assemble PASM programs into the various formats. These are wrappers over functions generated by the Rocq to OCaml extraction.