Permalink
Browse files

Fix cmp in 24bit mode #2

  • Loading branch information...
shinh committed Mar 15, 2016
1 parent 88d603b commit d93eb9f20cfdfefdd90e94d689f8e38837c606df
Showing with 12 additions and 5 deletions.
  1. +6 −4 bfasm.rb
  2. +6 −1 bfgen.rb
View
@@ -320,24 +320,26 @@ def emit_cmp(g, op, lhs, rhs)
g.move_ptr(WRK+2)
# If the RHS becomes zero at this moment, LHS >=
# RHS. Modify the next byte.
g.ifzero(4) do
g.ifzero(5) do
g.clear(WRK-1)
g.clear(WRK)
g.clear(WRK+1)
g.clear(WRK+3)
g.clear(WRK+4)
g.add(WRK+2, 1)
g.clear(WRK-1)
end
g.add(WRK+2, -1)
}
g.move_ptr(WRK+2)
g.ifzero(4, true) {
g.ifzero(4, true, '<<[-]>>') {
ge_rest[]
}
else
ge_rest[]
end
g.clear(WRK+1)
g.clear(WRK+2)
g.clear_word(WRK+3)
g.clear_word(WRK+6)
View
@@ -126,7 +126,7 @@ def save_ptr(&cb)
@mp = omp
end
def ifzero(off, reset=false, &cb)
def ifzero(off, reset=false, ifnz='', &cb)
omp = @mp
@mp = 0
@@ -136,6 +136,7 @@ def ifzero(off, reset=false, &cb)
if reset
emit '[-]'
end
emit ifnz
move_ptr(off)
emit ']'
move_ptr(off * 2)
@@ -165,6 +166,10 @@ def clear_word(ptr)
def dbg(msg, ptr)
return if !$verbose
info(msg, ptr)
end
def info(msg, ptr)
clear(ptr)
prev = 0
msg.each_byte{|b|

0 comments on commit d93eb9f

Please sign in to comment.