mirror of
https://github.com/irmen/prog8.git
synced 2025-01-12 19:29:50 +00:00
fix some asm
This commit is contained in:
parent
067426016d
commit
bcedb5f5e3
@ -20,7 +20,7 @@ sub start() {
|
|||||||
|
|
||||||
A++
|
A++
|
||||||
X++
|
X++
|
||||||
;AY++
|
AY++
|
||||||
|
|
||||||
A = ~X
|
A = ~X
|
||||||
A = not Y
|
A = not Y
|
||||||
|
@ -311,6 +311,10 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram,
|
|||||||
out("\tdex")
|
out("\tdex")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun replaceByteA() {
|
||||||
|
out("\tsta ${(ESTACK_LO+1).toHex()},x")
|
||||||
|
}
|
||||||
|
|
||||||
private fun pushMemByte(address: Int) {
|
private fun pushMemByte(address: Int) {
|
||||||
out("\tlda ${address.toHex()}")
|
out("\tlda ${address.toHex()}")
|
||||||
out("\tsta ${ESTACK_LO.toHex()},x")
|
out("\tsta ${ESTACK_LO.toHex()},x")
|
||||||
@ -338,6 +342,12 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram,
|
|||||||
out("\tdex")
|
out("\tdex")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun replaceWordAY() {
|
||||||
|
out("\tsta ${(ESTACK_LO+1).toHex()},x")
|
||||||
|
out("\ttya")
|
||||||
|
out("\tsta ${(ESTACK_HI+1).toHex()},x")
|
||||||
|
}
|
||||||
|
|
||||||
private fun pushMemWord(address: Int) {
|
private fun pushMemWord(address: Int) {
|
||||||
out("\tlda ${address.toHex()}")
|
out("\tlda ${address.toHex()}")
|
||||||
out("\tsta ${ESTACK_LO.toHex()},x")
|
out("\tsta ${ESTACK_LO.toHex()},x")
|
||||||
@ -373,16 +383,40 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram,
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun popByteA() {
|
private fun popByteA() {
|
||||||
|
// for operations that remove a value from the stack
|
||||||
out("\tinx")
|
out("\tinx")
|
||||||
out("\tlda ${ESTACK_LO.toHex()},x")
|
out("\tlda ${ESTACK_LO.toHex()},x")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun peekByteA() {
|
||||||
|
// for operations that modify a value on the stack
|
||||||
|
out("\tlda ${(ESTACK_LO+1).toHex()},x")
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun peekByte2A() {
|
||||||
|
// for operations that modify a value on the stack, 1 under the top
|
||||||
|
out("\tlda ${(ESTACK_LO+2).toHex()},x")
|
||||||
|
}
|
||||||
|
|
||||||
private fun popWordAY() {
|
private fun popWordAY() {
|
||||||
|
// for operations that remove a value from the stack
|
||||||
out("\ninx")
|
out("\ninx")
|
||||||
out("\tlda ${ESTACK_LO.toHex()},x")
|
out("\tlda ${ESTACK_LO.toHex()},x")
|
||||||
out("\tldy ${ESTACK_HI.toHex()},x")
|
out("\tldy ${ESTACK_HI.toHex()},x")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun peekWordAY() {
|
||||||
|
// for operations that modify a value on the stack
|
||||||
|
out("\tlda ${(ESTACK_LO+1).toHex()},x")
|
||||||
|
out("\tldy ${(ESTACK_HI+1).toHex()},x")
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun peekWord2AY() {
|
||||||
|
// for operations that modify a value on the stack, 1 under the top
|
||||||
|
out("\tlda ${(ESTACK_LO+2).toHex()},x")
|
||||||
|
out("\tldy ${(ESTACK_HI+2).toHex()},x")
|
||||||
|
}
|
||||||
|
|
||||||
private fun instr2asm(insIdx: Int, ins: Instruction, block: IntermediateProgram.ProgramBlock): Int {
|
private fun instr2asm(insIdx: Int, ins: Instruction, block: IntermediateProgram.ProgramBlock): Int {
|
||||||
if(ins is LabelInstr) {
|
if(ins is LabelInstr) {
|
||||||
if(ins.name==block.shortname)
|
if(ins.name==block.shortname)
|
||||||
@ -676,16 +710,16 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram,
|
|||||||
out("\tdec ${ins.callLabel}")
|
out("\tdec ${ins.callLabel}")
|
||||||
}
|
}
|
||||||
Opcode.ADD_UB, Opcode.ADD_B -> {
|
Opcode.ADD_UB, Opcode.ADD_B -> {
|
||||||
out("\tlda ${(ESTACK_LO+2).toHex()},x")
|
peekByte2A()
|
||||||
out("\tclc\n\tadc ${(ESTACK_LO+1).toHex()},x")
|
out("\tclc\n\tadc ${(ESTACK_LO+1).toHex()},x")
|
||||||
out("\tsta ${(ESTACK_LO+2).toHex()},x")
|
|
||||||
out("\tinx")
|
out("\tinx")
|
||||||
|
replaceByteA()
|
||||||
}
|
}
|
||||||
Opcode.SUB_UB, Opcode.SUB_B -> {
|
Opcode.SUB_UB, Opcode.SUB_B -> {
|
||||||
out("\tlda ${(ESTACK_LO+2).toHex()},x")
|
peekByte2A()
|
||||||
out("\tsec\n\tsbc ${(ESTACK_LO+1).toHex()},x")
|
out("\tsec\n\tsbc ${(ESTACK_LO+1).toHex()},x")
|
||||||
out("\tsta ${(ESTACK_LO+2).toHex()},x")
|
|
||||||
out("\tinx")
|
out("\tinx")
|
||||||
|
replaceByteA()
|
||||||
}
|
}
|
||||||
Opcode.POP_MEM_UB, Opcode.POP_MEM_B -> {
|
Opcode.POP_MEM_UB, Opcode.POP_MEM_B -> {
|
||||||
popByteA()
|
popByteA()
|
||||||
@ -703,25 +737,42 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram,
|
|||||||
out("\tsty ${ins.callLabel}+1")
|
out("\tsty ${ins.callLabel}+1")
|
||||||
}
|
}
|
||||||
Opcode.NEG_B -> {
|
Opcode.NEG_B -> {
|
||||||
popByteA()
|
peekByteA()
|
||||||
out("\teor #\$ff")
|
out("\teor #\$ff")
|
||||||
out("\tsec\n\tadc #0")
|
out("\tsec\n\tadc #0")
|
||||||
pushByteA()
|
replaceByteA()
|
||||||
}
|
}
|
||||||
Opcode.INV_BYTE, Opcode.NOT_BYTE -> {
|
Opcode.INV_BYTE -> {
|
||||||
popByteA()
|
peekByteA()
|
||||||
out("\teor #\$ff")
|
out("\teor #\$ff")
|
||||||
pushByteA()
|
replaceByteA()
|
||||||
}
|
}
|
||||||
Opcode.INV_WORD, Opcode.NOT_WORD -> {
|
Opcode.INV_WORD -> {
|
||||||
popWordAY()
|
out("\tlda ${(ESTACK_LO+1).toHex()},x")
|
||||||
out("\teor #\$ff")
|
out("\teor #\$ff")
|
||||||
out("\tpha")
|
out("\tlda ${(ESTACK_HI+1).toHex()},x")
|
||||||
out("\ttya")
|
|
||||||
out("\teor #\$ff")
|
out("\teor #\$ff")
|
||||||
out("\ttay")
|
out("\tsta ${(ESTACK_LO+1).toHex()},x")
|
||||||
out("\tpla")
|
out("\tsta ${(ESTACK_HI+1).toHex()},x")
|
||||||
pushWordAY()
|
}
|
||||||
|
Opcode.NOT_BYTE -> {
|
||||||
|
peekByteA()
|
||||||
|
out("\tbeq +")
|
||||||
|
out("\tlda #0")
|
||||||
|
out("\tbeq ++")
|
||||||
|
out("+\tlda #1")
|
||||||
|
out("++")
|
||||||
|
replaceByteA()
|
||||||
|
}
|
||||||
|
Opcode.NOT_WORD -> {
|
||||||
|
out("\tlda ${(ESTACK_LO+1).toHex()},x")
|
||||||
|
out("\tora ${(ESTACK_HI+1).toHex()},x")
|
||||||
|
out("\tbeq +")
|
||||||
|
out("\tlda #0")
|
||||||
|
out("\tbeq ++")
|
||||||
|
out("+\tlda #1")
|
||||||
|
out("++\tsta ${(ESTACK_LO+1).toHex()},x")
|
||||||
|
out("\tsta ${(ESTACK_HI+1).toHex()},x")
|
||||||
}
|
}
|
||||||
|
|
||||||
else-> TODO("asm for $ins")
|
else-> TODO("asm for $ins")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user