An assembler (and disassembler) for stepper motor ASIP code, written in Rust.
Requires cargo
.
cargo install --git https://github.com/BlakeFreer/asp.git
$ asp file.s
Output saved to out.mif
Add -o <FILENAME>
to change the output file.
Use -f
or --fmt
to change the output format.
$ asp file.s -f hex
Output saved to out.hex
You can use xxd -b out.hex
to view the raw machine code.
$ asp --hex file.hex -f asm
Output saved to out.asm
Download example.s
and example.hex
from the examples/
folder. They represent the same program written in assembly and machine code.
$ asp example.s -f hex
Output saved to out.hex
$ diff out.hex example.hex -s
Files out.hex and example.hex are identical
$ asp --hex example.hex -f asm
Output saved to out.s
$ diff out.s example.s -s
Files out.s and example.s are identical
There are 4 registers r0 r1 r2 r3
:
r0
,r1
: General purposer2
Stepper motor positionr3
Delay period
The immediates are either signed In
or unsigned Un
, where n
is the number of bits.
Comments start with a semicolon.
BR i ; jump i (I5) ops
BRZ i ; jump i (I5) ops if r0 == 0, else continue
ADDI rx, u ; add u (U3) to reg rx
SUBI rx, u ; subtract (U3) from reg rx
SR0 u ; set the lower 4 bits of r0 to u (U4)
SRH0 u ; set the upper 4 bits of r0 to u (U4)
CLR rx ; clear reg rx
MOV rd, rs ; copy the content of reg rs into rd
MOVR rx ; move the number of full-steps specified by rx
MOVRHS rx ; move the number of half-steps specified by rx
MOVA rx ; move to the absolute position specified in rx
PAUSE ; wait for the amount of time specified by r3