fix push() of signed values

This commit is contained in:
Irmen de Jong
2021-11-28 13:01:46 +01:00
parent 0a568f2530
commit d6abd72e55
3 changed files with 6 additions and 4 deletions

View File

@@ -174,11 +174,12 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
} }
private fun funcPush(fcall: IFunctionCall, func: FSignature) { private fun funcPush(fcall: IFunctionCall, func: FSignature) {
val signed = fcall.args[0].inferType(program).oneOf(DataType.BYTE, DataType.WORD)
if(func.name=="push") { if(func.name=="push") {
asmgen.assignExpressionToRegister(fcall.args[0], RegisterOrPair.A) asmgen.assignExpressionToRegister(fcall.args[0], RegisterOrPair.A, signed)
asmgen.out(" pha") asmgen.out(" pha")
} else { } else {
asmgen.assignExpressionToRegister(fcall.args[0], RegisterOrPair.AY) asmgen.assignExpressionToRegister(fcall.args[0], RegisterOrPair.AY, signed)
if (asmgen.isTargetCpu(CpuType.CPU65c02)) if (asmgen.isTargetCpu(CpuType.CPU65c02))
asmgen.out(" pha | phy") asmgen.out(" pha | phy")
else else

View File

@@ -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("weird target kind for inplace negate float ${target.kind}")
} }
} }
else -> throw AssemblyError("negate of invalid type") else -> throw AssemblyError("negate of invalid type $dt")
} }
} }

View File

@@ -14,8 +14,9 @@ main {
uword @shared uw uword @shared uw
ubyte @shared ub ubyte @shared ub
word @shared ww word @shared ww
byte @shared bb
push(127) push(-bb)
pop(ub) pop(ub)
txt.print_ub(ub) txt.print_ub(ub)
txt.nl() txt.nl()