changeset 1708:5bfed2eedc9d

Fixed flag calculation for sub instructions in CPU DSL
author Michael Pavone <pavone@retrodev.com>
date Mon, 28 Jan 2019 22:37:46 -0800
parents a16088324f30
children 9c058ea77b7a
files cpu_dsl.py
diffstat 1 files changed, 5 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/cpu_dsl.py	Mon Jan 28 21:30:23 2019 -0800
+++ b/cpu_dsl.py	Mon Jan 28 22:37:46 2019 -0800
@@ -240,8 +240,8 @@
 				decl,name = prog.getTemp(size)
 				dst = prog.carryFlowDst = name
 				prog.lastA = a
-				prog.lastB = '(-' + b + ')' if op == '-' else b
-				prog.lastWasSub = op == '-'
+				prog.lastB = b
+				prog.lastBFlow = '(-' + b + ')' if op == '-' else b
 			else:
 				dst = params[2]
 			return decl + '\n\t{dst} = {a} {op} {b};'.format(
@@ -313,11 +313,10 @@
 				resultBit = prog.paramSize(prog.lastDst)
 			elif calc == 'half':
 				resultBit = 4
-				fmt = '({a} ^ {b} ^ ~{res})' if prog.lastWasSub else '({a} ^ {b} ^ {res})'
-				myRes = fmt.format(a = prog.lastA, b = prog.lastB, res = lastDst)
+				myRes = '({a} ^ {b} ^ {res})'.format(a = prog.lastA, b = prog.lastB, res = lastDst)
 			elif calc == 'overflow':
 				resultBit = prog.paramSize(prog.lastDst) - 1
-				myRes = '((~({a} ^ {b})) & ({a} ^ {res}))'.format(a = prog.lastA, b = prog.lastB, res = lastDst)
+				myRes = '((~({a} ^ {b})) & ({a} ^ {res}))'.format(a = prog.lastA, b = prog.lastBFlow, res = lastDst)
 			else:
 				resultBit = int(resultBit)
 			if type(storage) is tuple:
@@ -991,7 +990,7 @@
 		self.carryFlowDst = None
 		self.lastA = None
 		self.lastB = None
-		self.lastWasSub = False
+		self.lastBFlow = None
 		
 	def __str__(self):
 		pieces = []