summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <lekensteyn@gmail.com>2011-11-28 21:00:56 +0000
committerPeter Wu <lekensteyn@gmail.com>2011-11-28 21:00:56 +0000
commit308fc185484231d3d73174b68f455c0578469373 (patch)
tree4a2575a33517d8f217c130e22c756e587a4bb2b0
parent83d005c9c6937236523ae15eaef792c8ef3dae06 (diff)
downloadpp2cc-308fc185484231d3d73174b68f455c0578469373.tar.gz
Fix right shift for -1 (all bits 1)
-rwxr-xr-xpp2cc.py2
1 files changed, 2 insertions, 0 deletions
diff --git a/pp2cc.py b/pp2cc.py
index a13be6f..5dce20c 100755
--- a/pp2cc.py
+++ b/pp2cc.py
@@ -551,6 +551,8 @@ class Parse(object):
lines.append(self.asm.binary_op("CMP", reg_first, 0))
# if it's positive, skip handling for negative values
lines.append(self.asm.branch_op("BPL", lbl_make_positive))
+ # -1 / 2 = 0, so make sure that the last bit is zero
+ lines.append(self.asm.binary_op("AND", reg_first, "%10"))
# shift it by one
lines.append(self.asm.binary_op("DIV", reg_first, 1))
# make it positive if not already