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.gtgreater thanf.ltless thanf.gegreater or equal tof.leless or equal tof.eqequal tof.nenot equal tof.errgeneral purpose error flagf.syserrsystem 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, SRCmoves SRC to DST
- functions
call Fcalls Fcallx Fcalls an extern Fretreturns from function
- stack
push SRCpushes SRC to stackpop DSTpops from stack to DST
- testing
cmp A, Bcompares A and Btest Atests if A is zeronotnegates last comparison
- boolean
cmpl DSTbinary complimentand DST, SRCbinary andor DST, SRCbinary orxor DST, SRCbinary xornand DST, SRCbinary nandnor DST, SRCbinary norxnor DST, SRCbinary xnor
- arithmetic
inc DSTincrements DSTdec DSTdecrements DSTadd DST, SRCadds SRC to DSTsub DST, SRCsubtracts SRC from DSTmul DST, SRCmultipies DST by srcdiv DST, SRCdivides 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>