A Lua-based assembly-like language designed for learning and teaching assembly.
asm.lua based on the x86 architecture. To Lua, it's what asm.js is it to JavaScript, except that it's not actually faster. It compiles to pure Lua and is implemented in pure Lua.
It is currently in very early development. asm.lua is not yet guaranteed to work and many features are subject to change.
To compile the examples, execute ./asm.lua examples/X.lua
, where X is any of
the examples included in the examples directory. This will create a file called
a.lua
that can be ran using the Lua interpreter, like so: lua a.lua
.
- general purpose registers (can be used for any operation (mostly)) (only numbers allowed here)
- A the accumulator
- B base index
- C counter
- D arithmetic
- string registers (only strings are allowed here)
- SS source string
- DS destination string
- F flag register
f.gt
greater thanf.lt
less thanf.ge
greater or equal tof.le
less or equal tof.eq
equal tof.ne
not equal tof.err
general purpose error flagf.syserr
system error flag
- SP stack pointer
Memory is divided into cells indexed by integers. Every cell holds a Lua variable (either a string or a number).
reserved for nil
cannot be changed
general purpose memory
stack
// TODO
<op> [dst], [src] -- comment
- data moving
mov DST, SRC
moves SRC to DST
- functions
call F
calls Fcallx F
calls an extern Fret
returns from function
- stack
push SRC
pushes SRC to stackpop DST
pops from stack to DST
- testing
cmp A, B
compares A and Btest A
tests if A is zeronot
negates last comparison
- boolean
cmpl DST
binary complimentand DST, SRC
binary andor DST, SRC
binary orxor DST, SRC
binary xornand DST, SRC
binary nandnor DST, SRC
binary norxnor DST, SRC
binary xnor
- arithmetic
inc DST
increments DSTdec DST
decrements DSTadd DST, SRC
adds SRC to DSTsub DST, SRC
subtracts SRC from DSTmul DST, SRC
multipies DST by srcdiv DST, SRC
divides DST by SRC
The bitwise operators require the Lua bitops library. It is currently not included by default, but is available by default when using LuaJIT.
cmp <dst>, <src> OR test <dst>
if <cond> then
... code
end
cond
can be gt
, lt
, ge
, le
, eq
, ne
, err
or syserr
repeat
... code
cmp <dst>, <src> OR test <dst>
until <cond>
cmp <dst>, <src> OR test <dst>
while <cond> do
... code
cmp <dst>, <src> OR test <dst>
end
loop
... code
end
The last one loops as long as register C is not 0.
<name>:
... code
ret
end
extern <name>
mov <extern-dst>, <any-src>
callx <extern-func>, <n>