Assembler for RISC-ALX architecture.
./rasm <INPUT_FILE>
INPUT_FILE must be valid RASM code.
Machine code will be sent to stdout.
There are four kinds of statements in RASM:
- Section declarations
- Register declarations
- Symbol declarations
- Instructions
Either .data
or .text
.
The statement .data
must be the first line of code in the file and precede .text
.
Register name followed by the integer value it is initialized to.
Can only exist in .data
section.
Example: tmp 10
.
Symbol name followed by a colon.
Can only exist in .text
section.
Example: _start:
.
An instruction from the following list followed by its operands.
Name | Operand 1 | Operand 2 | Description |
---|---|---|---|
jmp | Dest | Sets instruction pointer to Dest | |
jz | Dest | Source | Jumps to Dest if [Source] = 0 |
jnz | Dest | Source | Jumps to Dest if [Source] != 0 |
cmp | Addr1 | Addr2 | To be followed by je, jne, jg, jge, jl, or jle |
je | Dest | Jump to Dest if [Addr1] = [Addr2] | |
jne | Dest | Jump to Dest if [Addr1] != [Addr2] | |
jg | Dest | Jump to Dest if [Addr1] > [Addr2] | |
jge | Dest | Jump to Dest if [Addr1] >= [Addr2] | |
jl | Dest | Jump to Dest if [Addr1] < [Addr2] | |
jle | Dest | Jump to Dest if [Addr1] <= [Addr2] | |
inc | Dest | Increments [Dest] | |
add | Dest | Source | Stores [Dest] + [Source] into [Dest] |
sub | Dest | Source | Stores [Dest] - [Source] into [Dest] (Stores 0 if [Source] >= [Dest]) |
mov | Dest | Source | Copies [Source] to [Dest] |
drs | Dest | Source | Copies [[Source]] to [Dest] |
drt | Dest | Source | Copies [Source] to [[Dest]] |
out | Source | Outputs [Source] | |
inp | Dest | Inputs into [Dest] | |
hlt | Halts | ||
An operand can either be a register name, a symbol name, or a non-negative integer preceded by a dollar sign indicating a numerical constant. | |||
The symbol _start must be defined for all programs, as it acts as the starting point of execution. |
|||
The symbol __ram is a special symbol that is predefined and indicates the beginning of available memory. All memory past this point is free to alter without repercussion. |
An example of a program designed to list the first n fibonacci numbers where n is the given input:
.data
cur 0
next 1
tmp 0
count 0
.text
_start:
inp count
_repeat:
out cur
mov tmp next
add next cur
mov cur tmp
sub count $1
jnz _repeat count
_finish:
hlt
See RISC-ALX.md.
Support for syntax highlighting is provided through the VSCode extension syntax.vsix.