fork(3) download
  1. local output = {}
  2. local labels = {}
  3.  
  4. function mem(addr) return addr end
  5. function label(name) if name then labels[name] = #output end end
  6.  
  7. local g = {}
  8. setmetatable(_G, {
  9. __index = function(t, k, v) return g[k] end,
  10. __newindex = function(t, k, v)
  11. if g[k] then table.insert(output, {g[k], v})
  12. else g[k]=v end
  13. end
  14. })
  15.  
  16. setmetatable(output, {
  17. __gc = function(o)
  18. for _,v in ipairs(o) do
  19. if type(v[2]) == "string" then v[2] = labels[v[2]] or print("wrong label: ", v[2]) end
  20. print(string.format("%02X%02X", v[1] & 0xFF, v[2] & 0xFF))
  21. end
  22. end
  23. })
  24.  
  25.  
  26.  
  27. PC = mem(0)
  28. CG = mem(1)
  29. TST = mem(2)
  30. ADD = mem(3)
  31. SUB = mem(4)
  32. PORT = mem(5)
  33.  
  34. cnt = mem(7)
  35.  
  36. function jmp(l)
  37. CG = l
  38. PC = CG
  39. end
  40.  
  41. label "start"
  42. CG = 0
  43. cnt = CG
  44. PORT = CG
  45.  
  46. label "loop"
  47. CG = 1
  48. ADD = cnt -- add = cnt + 1
  49. cnt = ADD
  50. PORT = ADD
  51.  
  52. CG = -5
  53. ADD = ADD --add = add + 256 - 5
  54. CG = "loop"
  55. TST = ADD --skip "exit" if not 0
  56. CG = "exit"
  57. PC = CG
  58.  
  59. label "exit"
  60. jmp "exit"
Success #stdin #stdout 0s 14112KB
stdin
Standard input is empty
stdout
0100
0701
0501
0101
0307
0703
0503
01FB
0303
0103
0203
010D
0001
010D
0001