programstart = 000 output = {} labeltable = {} pointertable = {} program = [[Psh &string @loop Dup Lds ; end if encounter null byte Dup Psh 2 rcjQ Hlt Psh -101 Str Psh 1 Add Psh &loop Jmp @string ; Hello, World! 72 101 108 108 111 44 32 87 111 114 108 100 33 10 0 ]] --program = "" if program == "" then f = io.open("program.asm") x = "" while x ~= nil do program = program .. x x = f:read(128) end end char = "" charindex = 1 opcodetable = { 09, 14, 16, 03, 17, 19, 06, 21, -1, 15, 05, 07, 11, 13, 00, 01, 18, 20, 08, -1, 10, 02, 04, -1, -1, -1 } function getchar() char = program:sub(charindex,charindex) if char == nil then error("EOF!") end charindex = charindex + 1 return char end function backchar() charindex = charindex - 1 end function isdigit(char) return tonumber(char) ~= nil end function islower(char) return string.upper(char) ~= char end function isupper(char) return string.lower(char) ~= char end function getword() word = "" while islower(getchar()) do word = word..char end backchar() return word end function parsenumber() num = char while isdigit(getchar()) do num = num..char end backchar() table.insert(output, tonumber(num..".0")) end while charindex < #program do getchar() if char == "@" then labeltable[getword()] = #output elseif char == "&" then pointertable[#output] = getword() table.insert(output, -0) elseif char == ";" then while char ~= "\n" do getchar() end elseif char == "-" then parsenumber() elseif isdigit(char) then parsenumber() elseif isupper(char) then table.insert(output, opcodetable[string.byte(char)-string.byte("A")+1]) end end for a,l in pairs(pointertable) do if labeltable[l]==nil then error(l.." doest exist, addr ", a) end output[a+1] = labeltable[l] end hash = 0 for i,n in ipairs(output) do hash = hash+n io.write(n,",") end print("\n") print(#output) print(hash)