@@ -465,7 +465,7 @@ internal class ProgramAndVarsGen(
465465
466466 private fun zeropagevars2asm (varNames : Set <String >) {
467467 val namesLists = varNames.map { it.split(' .' ) }.toSet()
468- val zpVariables = allocator.zeropageVars.filter { it.key in namesLists }
468+ val zpVariables = allocator.zeropageVars.filter { it.key in namesLists }.toList().sortedBy { it.second.address }
469469 for ((scopedName, zpvar) in zpVariables) {
470470 if (scopedName.size == 2 && scopedName[0 ] == " cx16" && scopedName[1 ][0 ] == ' r' && scopedName[1 ][1 ].isDigit())
471471 continue // The 16 virtual registers of the cx16 are not actual variables in zp, they're memory mapped
@@ -476,7 +476,7 @@ internal class ProgramAndVarsGen(
476476 private fun nonZpVariables2asm (variables : List <StStaticVariable >) {
477477 asmgen.out (" " )
478478 asmgen.out (" ; non-zeropage variables" )
479- val (stringvars, othervars) = variables.partition { it.dt== DataType .STR }
479+ val (stringvars, othervars) = variables.sortedBy { it.name }. partition { it.dt== DataType .STR }
480480 stringvars.forEach {
481481 outputStringvar(it.name, it.onetimeInitializationStringValue!! .second, it.onetimeInitializationStringValue!! .first)
482482 }
@@ -582,10 +582,10 @@ internal class ProgramAndVarsGen(
582582 }
583583
584584 private fun memdefsAndConsts2asm (memvars : Collection <StMemVar >, consts : Collection <StConstant >) {
585- memvars.forEach {
585+ memvars.sortedBy { it.address }. forEach {
586586 asmgen.out (" ${it.name} = ${it.address.toHex()} " )
587587 }
588- consts.forEach {
588+ consts.sortedBy { it.name }. forEach {
589589 if (it.dt== DataType .FLOAT )
590590 asmgen.out (" ${it.name} = ${it.value} " )
591591 else
0 commit comments