From 63332c05303b9df6e7ff28585c6214f4cfbc0b5c Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Tue, 8 Dec 2020 21:29:40 +0100 Subject: [PATCH] fix wrong branch instructions for some if_xxx --- .../compiler/target/c64/codegen/AsmGen.kt | 10 ++++---- examples/test.p8 | 23 +++++++++---------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt b/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt index 44a59b32f..7e32abb0c 100644 --- a/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt @@ -814,12 +814,12 @@ internal class AsmGen(private val program: Program, when (condition) { BranchCondition.CS -> "bcc" BranchCondition.CC -> "bcs" - BranchCondition.EQ, BranchCondition.Z -> "beq" - BranchCondition.NE, BranchCondition.NZ -> "bne" + BranchCondition.EQ, BranchCondition.Z -> "bne" + BranchCondition.NE, BranchCondition.NZ -> "beq" BranchCondition.VS -> "bvc" BranchCondition.VC -> "bvs" - BranchCondition.MI, BranchCondition.NEG -> "bmi" - BranchCondition.PL, BranchCondition.POS -> "bpl" + BranchCondition.MI, BranchCondition.NEG -> "bpl" + BranchCondition.PL, BranchCondition.POS -> "bmi" } } else { when (condition) { @@ -1071,7 +1071,7 @@ $counterVar .byte 0""") val jump = stmt.truepart.statements.first() as? Jump if(jump!=null) { - // branch with only a jump + // branch with only a jump (goto) val instruction = branchInstruction(stmt.condition, false) out(" $instruction ${getJumpTarget(jump)}") translate(stmt.elsepart) diff --git a/examples/test.p8 b/examples/test.p8 index 85102c4df..f79a34388 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -8,6 +8,16 @@ errors { sub tofix() { + repeat { + ubyte char3 = c64.CHRIN() + if_z + goto labeltje + if_z + break ; TODO wrong jump asm generated, works fine if you use a label instead to jump to + } +labeltje: + + while c64.CHRIN() { ; TODO: the loop condition isn't properly tested because a ldx is in the way before the beq } @@ -18,12 +28,6 @@ errors { break } - repeat { - ubyte char3 = c64.CHRIN() - if_z - break ; TODO wrong jump asm generated, works fine if you use a label instead to jump to - } - ; TODO fix undefined symbol: repeat { ubyte char = c64.CHRIN() @@ -40,12 +44,7 @@ errors { main { sub start() { - function(&start) + errors.tofix() test_stack.test() } - - sub function(uword param) { - txt.print_uwhex(param, 1) - param++ - } }