esAsm is a toy assembly-like language
raco pkg install esAsm
- Each line in an esAsm file may contain whitespace, a comment, a label, or an instruction.
- Comment lines begin with
;and are ignored. Lines starting with#lang esAsmare also ignored. - Labels are indicated with the suffix
:. The:is not part of the label name when referenced elsewhere. - Literal integers are prefixed with
#, and register references are prefixed withr. The registers arer0-r11. - Program execution is moved to the beginning of a file when the end is reached. It will continue looping until the
hltinstruction.
In this documentation, val means any literal or register, reg means a register, and lab means a label.
shn valprints the numeric value ofval.sha valprints the ascii character with the decimal valueval.mov reg valsets the value ofregtoval.add reg val1 val2sets the value ofregtoval1+val2.sub reg val1 val2sets the value ofregtoval1-val2.jmp labmoves the program execution tolab.jlt lab val1 val2moves the program execution tolabifval1<val2.jgt lab val1 val2moves the program execution tolabifval1>val2.jet lab val1 val2moves the program execution tolabifval1==val2.inp regsets the value ofregto an integer from read from stdin.hltends the execution of the program.mficofsr regsets the value ofregto the value of the "Is Computer On Fire" status register. See here.
There are a few examples in the examples/ directory.
read-six-numbers.es.rktreads six numbers and prints their sum.is-even.es.rktprintsYif the given number is even andNif it's odd.compare.es.rktprintsG,L, orEif the first number is respectively greater, less, or equal to the second.fibonacci.es.rktprints the first 10 terms of the Fibonacci sequence.factors.es.rktprints the factors of a given number.no-jump.es.rktdemonstrates the branchless sublanguage.
For testing purposes, inp is replaced (commented) in the examples.
| Name | Summary | Syntax |
|---|---|---|
| shn | Show as number | shn val |
| sha | Show as ascii | sha val |
| mov | Move | mov reg val |
| add | Add | add reg val1 val2 |
| sub | Subtract | sub reg val1 val2 |
| jmp | Jump | jmp lab |
| jlt | Jump if less than | jlt lab val1 val2 |
| jgt | Jump if greater than | jgt lab val1 val2 |
| jet | Jump if equal to | jet lab val1 val2 |
| inp | Input | inp reg |
| hlt | Halt | hlt |
| mficofsr | Move From Is Computer On Fire Status Register | mficofsr reg |
All contributions are welcome by pull request or issue, especially new instructions.
Behavior of esAsm is undefined if the computer is on fire.
esAsm is licensed under the MIT license. See LICENSE for full text.