From 73dfb5f4435da2b30aac79af53bff3657c6906ac Mon Sep 17 00:00:00 2001 From: Natt Akuma Date: Fri, 4 Feb 2022 00:59:44 +0700 Subject: [PATCH] Optimize sign extension to AY --- codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt | 8 +++++++- compiler/res/prog8lib/prog8_lib.asm | 14 -------------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt index d85bca51a..b146fe260 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt @@ -1707,7 +1707,13 @@ $repeatLabel lda $counterVar // sign extend signed byte in A to full word in AY when(valueDt) { DataType.UBYTE -> out(" ldy #0") - DataType.BYTE -> out(" jsr prog8_lib.sign_extend_AY_byte") + DataType.BYTE -> out(""" + ldy #0 + cmp #$80 + bcc + + dey ++ + """) else -> throw AssemblyError("need byte type") } } diff --git a/compiler/res/prog8lib/prog8_lib.asm b/compiler/res/prog8lib/prog8_lib.asm index 3b87301af..acbbaf41c 100644 --- a/compiler/res/prog8lib/prog8_lib.asm +++ b/compiler/res/prog8lib/prog8_lib.asm @@ -1158,20 +1158,6 @@ sign_extend_stack_byte .proc rts .pend - -sign_extend_AY_byte .proc - ; -- sign extend the (signed) byte in AY to full 16 bits - pha - and #$80 - beq + - ldy #$ff - pla - rts -+ ldy #0 - pla - rts - .pend - strlen .proc ; -- returns the number of bytes in the string in AY, in Y. sta P8ZP_SCRATCH_W1