From fbe20a240b1e0a27a78a0536b4df418a42dc48d7 Mon Sep 17 00:00:00 2001 From: Karol Stasiak Date: Mon, 24 Jun 2019 00:13:02 +0200 Subject: [PATCH] 8080: Fix division --- .../millfork/compiler/z80/Z80ExpressionCompiler.scala | 2 +- src/main/scala/millfork/compiler/z80/Z80Multiply.scala | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/scala/millfork/compiler/z80/Z80ExpressionCompiler.scala b/src/main/scala/millfork/compiler/z80/Z80ExpressionCompiler.scala index fffa4fe0..e901ab1e 100644 --- a/src/main/scala/millfork/compiler/z80/Z80ExpressionCompiler.scala +++ b/src/main/scala/millfork/compiler/z80/Z80ExpressionCompiler.scala @@ -968,7 +968,7 @@ object Z80ExpressionCompiler extends AbstractExpressionCompiler[ZLine] { } case "/" | "%%" => assertSizesForDivision(ctx, params, inPlace = false) - val (l, r, size) = assertArithmeticAssignmentLike(ctx, params) + val (l, r, size) = assertArithmeticBinary(ctx, params) size match { case 1 => targetifyA(ctx, target, Z80Multiply.compileUnsignedByteDivision(ctx, Right(l), r, f.functionName == "%%"), isSigned = false) diff --git a/src/main/scala/millfork/compiler/z80/Z80Multiply.scala b/src/main/scala/millfork/compiler/z80/Z80Multiply.scala index 2754106b..cc70518f 100644 --- a/src/main/scala/millfork/compiler/z80/Z80Multiply.scala +++ b/src/main/scala/millfork/compiler/z80/Z80Multiply.scala @@ -106,7 +106,7 @@ object Z80Multiply { /** * Calculate HL = p / q and A = p %% q */ - def compileUnsignedWordByByteDivision(ctx: CompilationContext, p: Either[LocalVariableAddressOperand, LhsExpression], q: Expression): List[ZLine] = { + def compileUnsignedWordByByteDivision(ctx: CompilationContext, p: Either[LocalVariableAddressOperand, Expression], q: Expression): List[ZLine] = { val pb = p match { case Right(pp) => Z80ExpressionCompiler.compileToHL(ctx, pp) case Left(LocalVariableAddressViaHL) => List( @@ -122,7 +122,7 @@ object Z80Multiply { val load = if (qb.exists(Z80ExpressionCompiler.changesHL)) { pb ++ Z80ExpressionCompiler.stashHLIfChanged(ctx, qb) } else if (pb.exists(Z80ExpressionCompiler.changesDE)) { - qb ++ List(ZLine.ld8(ZRegister.D, ZRegister.A)) ++ Z80ExpressionCompiler.stashDEIfChanged(ctx, qb) + qb ++ List(ZLine.ld8(ZRegister.D, ZRegister.A)) ++ Z80ExpressionCompiler.stashDEIfChanged(ctx, pb) } else { pb ++ qb ++ List(ZLine.ld8(ZRegister.D, ZRegister.A)) } @@ -132,7 +132,7 @@ object Z80Multiply { /** * Calculate A = p / q or A = p %% q */ - def compileUnsignedByteDivision(ctx: CompilationContext, p: Either[LocalVariableAddressOperand, LhsExpression], q: Expression, modulo: Boolean): List[ZLine] = { + def compileUnsignedByteDivision(ctx: CompilationContext, p: Either[LocalVariableAddressOperand, Expression], q: Expression, modulo: Boolean): List[ZLine] = { def loadPToA(): List[ZLine] = { p match { case Right(pp) => Z80ExpressionCompiler.compileToA(ctx, pp) @@ -179,7 +179,7 @@ object Z80Multiply { /** * Calculate A = p / q or A = p %% q */ - def compileUnsignedByteDivisionImpl(ctx: CompilationContext, p: Either[LocalVariableAddressOperand, LhsExpression], q: Int, modulo: Boolean): List[ZLine] = { + def compileUnsignedByteDivisionImpl(ctx: CompilationContext, p: Either[LocalVariableAddressOperand, Expression], q: Int, modulo: Boolean): List[ZLine] = { import ZRegister._ import ZOpcode._ val result = ListBuffer[ZLine]()