}
builtin('load-imm') {
+ reg = pop()
+ val = pop()
+ if val == 0 then
+ if reg <= 7 then
+ packBytes([0x48, 0x31, 0xc0 + (reg * 9)])
+ else
+ packBytes([0x4d, 0x31, 0xc0 + ((reg - 8) * 9)])
+ end
+ else
+ if reg <= 7 then
+ packBytes([0x48, 0xC7, 0xc0 | reg])
+ else
+ packBytes([0x49, 0xC7, 0xc0 | (reg - 8)])
+ end
+ pack32(val)
+ end
}
builtin('syscall') {
}
-
#------------------------------------------
# Input Interpreter
#------------------------------------------
-
-loop do
- $words['word'].code.call()
- w = $stack.pop
- next if w.nil? or w.length == 0
- if $words[w] then
- if $state == 0 || (($words[w].flags & IMM) == IMM)
- $words[w].code.call
- else
- $curr.code << $words[w].code
- end
- elsif w =~ /^[0-9]+$/
- if $state == 0
- push w.to_i
+def interp()
+ while (not $input.eof?) || ($buffer.length > 0) do
+ $words['word'].code.call()
+ w = $stack.pop
+ next if w.nil? or w.length == 0
+ if $words[w] then
+ if $state == 0 || (($words[w].flags & IMM) == IMM)
+ $words[w].code.call
+ else
+ $curr.code << $words[w].code
+ end
+ elsif w =~ /^[0-9]+$/
+ if $state == 0
+ push w.to_i
+ else
+ $curr.code << lambda{ push w.to_i }
+ end
else
- $curr.code << lambda{ push w.to_i }
+ pp $stack
+ puts "?"
+ $stack = []
end
- else
- pp $stack
- puts "?"
- $stack = []
end
end
+def interp_file(file)
+ prev = $input
+ $input = File.open(file, "rb")
+ interp()
+ $input = prev
+end
+
+
+interp_file("asm.s")
#$stdin.each_line do |line|
# line.split.each do |w|
# end
#end
#
-## Set program length and write to disk
-#PROG[96] = ((PROG.length >> 0) & 0xFF)
-#PROG[97] = ((PROG.length >> 8) & 0xFF)
-#PROG[98] = ((PROG.length >> 16) & 0xFF)
-#PROG[99] = ((PROG.length >> 24) & 0xFF)
-#File.binwrite("a.out", PROG.map{|b| b.chr }.join)
+# Set program length and write to disk
+PROG[96] = ((PROG.length >> 0) & 0xFF)
+PROG[97] = ((PROG.length >> 8) & 0xFF)
+PROG[98] = ((PROG.length >> 16) & 0xFF)
+PROG[99] = ((PROG.length >> 24) & 0xFF)
+File.binwrite("a.out", PROG.map{|b| b.chr }.join)