Added the simple assembler

This commit is contained in:
Izaya 2016-12-11 16:04:53 +11:00
parent 733e3c3cb1
commit f29fb5fbd8
1 changed files with 40 additions and 0 deletions

40
sasm.lua Normal file
View File

@ -0,0 +1,40 @@
tArgs = {...}
insd = {[4095] = "dup",
[4094] = "swp",
[4093] = "read",
[4092] = "write",
[4091] = "add",
[4090] = "sub",
[4089] = "jmp",
[4088] = "sez"}
insc = {}
insc.dup = 4095
insc.swp = 4094
insc.read = 4093
insc.write = 4092
insc.add = 4091
insc.sub = 4090
insc.jmp = 4089
insc.sez = 4088
f = io.open(tArgs[2],"rb")
if not f then error("file inaccessable") end
c = f:read("*a")
f:close()
for w in c:gmatch("%S+") do
if tArgs[1] == "-c" then
if insc[w] ~= nil then
print(insc[w])
else
print(w)
end
elseif tArgs[1] == "-d" then
if insd[tonumber(w)] ~= nil then
print(insd[tonumber(w)])
else
print(w)
end
end
end