improved setting Carry bit as asmsub parameter

This commit is contained in:
Irmen de Jong 2021-11-28 03:05:46 +01:00
parent 1b07637cc4
commit f3a4048ebf
6 changed files with 32 additions and 28 deletions

View File

@ -88,8 +88,15 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
"push/pop arg passing only supported on asmsubs ${(fcall as Node).position}"
}
val reg = sub.asmParameterRegisters[sub.parameters.indexOf(parameter)]
if(reg.statusflag!=null)
TODO("can't assign value to processor statusflag directly")
if(reg.statusflag!=null) {
asmgen.out("""
sta P8ZP_SCRATCH_REG
clc
pla
beq +
sec
+ lda P8ZP_SCRATCH_REG""")
}
else {
if (func.name == "pop") {
if (asmgen.isTargetCpu(CpuType.CPU65c02)) {

View File

@ -103,7 +103,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
Statusflag.Pc -> {
asmgen.out("""
lda #0
adc #0
rol a
sta P8ESTACK_LO,x
dex""")
}

View File

@ -214,11 +214,10 @@ internal class FunctionCallAsmGen(private val program: Program, private val asmg
if(argForCarry!=null) {
val plusIdxStr = if(argForCarry.index==0) "" else "+${argForCarry.index}"
asmgen.out("""
clc
lda P8ESTACK_LO$plusIdxStr,x
beq +
sec
bcs ++
+ clc
+ php""") // push the status flags
}
@ -297,11 +296,10 @@ internal class FunctionCallAsmGen(private val program: Program, private val asmg
val sourceName = asmgen.asmVariableName(value)
asmgen.out("""
pha
clc
lda $sourceName
beq +
sec
bcs ++
+ clc
+ pla
""")
}

View File

@ -327,8 +327,8 @@ private fun writeAssembly(program: Program,
program.processAstBeforeAsmGeneration(compilerOptions, errors)
errors.report()
println("*********** AST RIGHT BEFORE ASM GENERATION *************")
printProgram(program)
// println("*********** AST RIGHT BEFORE ASM GENERATION *************")
// printProgram(program)
compilerOptions.compTarget.machine.initializeZeropage(compilerOptions)
val assembly = asmGeneratorFor(compilerOptions.compTarget,

View File

@ -415,6 +415,8 @@ internal class StatementReorderer(val program: Program,
return modifications + IAstModification.ReplaceNode(call, GoSub(null, call.target, null, call.position), parent)
} else if(!options.compTarget.asmsubArgsHaveRegisterClobberRisk(call.args)) {
// no register clobber risk, let the asmgen assign values to the registers directly.
// this is more efficient than first evaluating them to the stack
// TODO but what about complex expressions?
return noModifications
} else {
// clobber risk; evaluate the arguments on the CPU stack first (in reverse order)...

View File

@ -11,15 +11,10 @@ main {
sub start() {
test_stack.test()
c64.SETNAM(string.length(filenameptr), filenameptr)
uword @shared uw
ubyte @shared ub
word @shared ww
sys.memcopy(&savedata + 2, cargohold, len(cargohold))
sys.memcopy(cargohold, &savedata + 2, len(cargohold))
; uword @shared uw
; ubyte @shared ub
; word @shared ww
;
; push(127)
; pop(ub)
; txt.print_ub(ub)
@ -28,13 +23,13 @@ main {
; popw(uw)
; txt.print_uw(uw)
; txt.nl()
;
; uw=10000
; routines(44,uw+123)
; routines2(44,uw+123)
;
; routine(uw+123, 22,33, true, 44)
; routine2(uw+123, 22,33, true, 44)
uw=10000
routines(44,uw+123)
routines2(44,uw+123)
routine(uw+123, 22,33, true, 44)
routine2(uw+123, 22,33, true, 44)
test_stack.test()
@ -63,17 +58,19 @@ main {
txt.nl()
}
; TODO make switch R3 use Pc instead and make that work !
asmsub routine2(uword num @AY, ubyte a1 @R1, ubyte a2 @R2, ubyte switch @R3, ubyte a3 @X) {
asmsub routine2(uword num @AY, ubyte a1 @R1, ubyte a2 @R2, ubyte switch @Pc, ubyte a3 @X) {
%asm {{
pha
lda #0
adc #0
sta routine.switch
pla
sta routine.num
sty routine.num+1
lda cx16.r1
sta routine.a1
lda cx16.r2
sta routine.a2
lda cx16.r3
sta routine.switch
stx routine.a3
jmp routine
}}