mirror of
https://github.com/KarolS/millfork.git
synced 2025-01-12 03:30:09 +00:00
8080: Fix division
This commit is contained in:
parent
0205520bf9
commit
fbe20a240b
@ -968,7 +968,7 @@ object Z80ExpressionCompiler extends AbstractExpressionCompiler[ZLine] {
|
|||||||
}
|
}
|
||||||
case "/" | "%%" =>
|
case "/" | "%%" =>
|
||||||
assertSizesForDivision(ctx, params, inPlace = false)
|
assertSizesForDivision(ctx, params, inPlace = false)
|
||||||
val (l, r, size) = assertArithmeticAssignmentLike(ctx, params)
|
val (l, r, size) = assertArithmeticBinary(ctx, params)
|
||||||
size match {
|
size match {
|
||||||
case 1 =>
|
case 1 =>
|
||||||
targetifyA(ctx, target, Z80Multiply.compileUnsignedByteDivision(ctx, Right(l), r, f.functionName == "%%"), isSigned = false)
|
targetifyA(ctx, target, Z80Multiply.compileUnsignedByteDivision(ctx, Right(l), r, f.functionName == "%%"), isSigned = false)
|
||||||
|
@ -106,7 +106,7 @@ object Z80Multiply {
|
|||||||
/**
|
/**
|
||||||
* Calculate HL = p / q and A = p %% q
|
* 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 {
|
val pb = p match {
|
||||||
case Right(pp) => Z80ExpressionCompiler.compileToHL(ctx, pp)
|
case Right(pp) => Z80ExpressionCompiler.compileToHL(ctx, pp)
|
||||||
case Left(LocalVariableAddressViaHL) => List(
|
case Left(LocalVariableAddressViaHL) => List(
|
||||||
@ -122,7 +122,7 @@ object Z80Multiply {
|
|||||||
val load = if (qb.exists(Z80ExpressionCompiler.changesHL)) {
|
val load = if (qb.exists(Z80ExpressionCompiler.changesHL)) {
|
||||||
pb ++ Z80ExpressionCompiler.stashHLIfChanged(ctx, qb)
|
pb ++ Z80ExpressionCompiler.stashHLIfChanged(ctx, qb)
|
||||||
} else if (pb.exists(Z80ExpressionCompiler.changesDE)) {
|
} 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 {
|
} else {
|
||||||
pb ++ qb ++ List(ZLine.ld8(ZRegister.D, ZRegister.A))
|
pb ++ qb ++ List(ZLine.ld8(ZRegister.D, ZRegister.A))
|
||||||
}
|
}
|
||||||
@ -132,7 +132,7 @@ object Z80Multiply {
|
|||||||
/**
|
/**
|
||||||
* Calculate A = p / q or A = p %% q
|
* 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] = {
|
def loadPToA(): List[ZLine] = {
|
||||||
p match {
|
p match {
|
||||||
case Right(pp) => Z80ExpressionCompiler.compileToA(ctx, pp)
|
case Right(pp) => Z80ExpressionCompiler.compileToA(ctx, pp)
|
||||||
@ -179,7 +179,7 @@ object Z80Multiply {
|
|||||||
/**
|
/**
|
||||||
* Calculate A = p / q or A = p %% q
|
* 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 ZRegister._
|
||||||
import ZOpcode._
|
import ZOpcode._
|
||||||
val result = ListBuffer[ZLine]()
|
val result = ListBuffer[ZLine]()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user