From f29fb5fbd8be0f99c59514fd481e85001f1d279e Mon Sep 17 00:00:00 2001 From: Izaya Orihara Date: Sun, 11 Dec 2016 16:04:53 +1100 Subject: [PATCH] Added the simple assembler --- sasm.lua | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 sasm.lua diff --git a/sasm.lua b/sasm.lua new file mode 100644 index 0000000..a8ac70c --- /dev/null +++ b/sasm.lua @@ -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