From d6abd72e55250bc6b0fac3cee2972b5368bc7e48 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sun, 28 Nov 2021 13:01:46 +0100 Subject: [PATCH] fix push() of signed values --- .../target/cpu6502/codegen/BuiltinFunctionsAsmGen.kt | 5 +++-- .../codegen/assignment/AugmentableAssignmentAsmGen.kt | 2 +- examples/test.p8 | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/BuiltinFunctionsAsmGen.kt b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/BuiltinFunctionsAsmGen.kt index 7baf66a0e..3e40b79e1 100644 --- a/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/BuiltinFunctionsAsmGen.kt +++ b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/BuiltinFunctionsAsmGen.kt @@ -174,11 +174,12 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val } private fun funcPush(fcall: IFunctionCall, func: FSignature) { + val signed = fcall.args[0].inferType(program).oneOf(DataType.BYTE, DataType.WORD) if(func.name=="push") { - asmgen.assignExpressionToRegister(fcall.args[0], RegisterOrPair.A) + asmgen.assignExpressionToRegister(fcall.args[0], RegisterOrPair.A, signed) asmgen.out(" pha") } else { - asmgen.assignExpressionToRegister(fcall.args[0], RegisterOrPair.AY) + asmgen.assignExpressionToRegister(fcall.args[0], RegisterOrPair.AY, signed) if (asmgen.isTargetCpu(CpuType.CPU65c02)) asmgen.out(" pha | phy") else diff --git a/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/assignment/AugmentableAssignmentAsmGen.kt b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/assignment/AugmentableAssignmentAsmGen.kt index b20da9515..8bac39057 100644 --- a/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/assignment/AugmentableAssignmentAsmGen.kt +++ b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/assignment/AugmentableAssignmentAsmGen.kt @@ -2083,7 +2083,7 @@ internal class AugmentableAssignmentAsmGen(private val program: Program, else -> throw AssemblyError("weird target kind for inplace negate float ${target.kind}") } } - else -> throw AssemblyError("negate of invalid type") + else -> throw AssemblyError("negate of invalid type $dt") } } diff --git a/examples/test.p8 b/examples/test.p8 index 2c3b7177c..0c3063b36 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -14,8 +14,9 @@ main { uword @shared uw ubyte @shared ub word @shared ww + byte @shared bb - push(127) + push(-bb) pop(ub) txt.print_ub(ub) txt.nl()