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/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt index 59f47857b..faba060a4 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt @@ -1158,17 +1158,16 @@ internal class AugmentableAssignmentAsmGen(private val program: Program, +""") else asmgen.out(""" - ldy #0 + ldy #255 lda $otherName bpl + - dey ; sign extend -+ sty P8ZP_SCRATCH_B1 - lda $name + iny ; sign extend ++ eor #255 sec - sbc $otherName + adc $name sta $name - lda $name+1 - sbc P8ZP_SCRATCH_B1 + tya + adc $name+1 sta $name+1""") } "*" -> { @@ -1446,29 +1445,28 @@ internal class AugmentableAssignmentAsmGen(private val program: Program, sta $name+1""") } "-" -> { - asmgen.assignExpressionToVariable(value, "P8ZP_SCRATCH_REG", valueDt, null) + asmgen.assignExpressionToVariable(value, "P8ZP_SCRATCH_B1", valueDt, null) if(valueDt==DataType.UBYTE) asmgen.out(""" lda $name sec - sbc P8ZP_SCRATCH_REG + sbc P8ZP_SCRATCH_B1 sta $name bcs + dec $name+1 +""") else asmgen.out(""" - ldy #0 - lda P8ZP_SCRATCH_REG + ldy #255 + lda P8ZP_SCRATCH_B1 bpl + - dey ; sign extend -+ sty P8ZP_SCRATCH_B1 - lda $name + iny ; sign extend ++ eor #255 sec - sbc P8ZP_SCRATCH_REG + adc $name sta $name - lda $name+1 - sbc P8ZP_SCRATCH_B1 + tya + adc $name+1 sta $name+1""") } "*" -> { @@ -2105,40 +2103,38 @@ internal class AugmentableAssignmentAsmGen(private val program: Program, when(target.register!!) { //P8ZP_SCRATCH_REG RegisterOrPair.AX -> { asmgen.out(""" - sta P8ZP_SCRATCH_REG - stx P8ZP_SCRATCH_REG+1 - lda #0 sec - sbc P8ZP_SCRATCH_REG + eor #255 + adc #0 pha - lda #0 - sbc P8ZP_SCRATCH_REG+1 + txa + eor #255 + adc #0 tax pla""") } RegisterOrPair.AY -> { asmgen.out(""" - sta P8ZP_SCRATCH_REG - sty P8ZP_SCRATCH_REG+1 - lda #0 sec - sbc P8ZP_SCRATCH_REG + eor #255 + adc #0 pha - lda #0 - sbc P8ZP_SCRATCH_REG+1 + tya + eor #255 + adc #0 tay pla""") } RegisterOrPair.XY -> { asmgen.out(""" - stx P8ZP_SCRATCH_REG - sty P8ZP_SCRATCH_REG+1 - lda #0 sec - sbc P8ZP_SCRATCH_REG + txa + eor #255 + adc #0 tax - lda #0 - sbc P8ZP_SCRATCH_REG+1 + tya + eor #255 + adc #0 tay""") } in Cx16VirtualRegisters -> throw AssemblyError("cx16 virtual regs should be variables, not real registers") diff --git a/compiler/res/prog8lib/prog8_lib.asm b/compiler/res/prog8lib/prog8_lib.asm index 3b87301af..ba0b1a501 100644 --- a/compiler/res/prog8lib/prog8_lib.asm +++ b/compiler/res/prog8lib/prog8_lib.asm @@ -1121,17 +1121,15 @@ strcmp_mem .proc ; Returns -1,0,1 in A, depeding on the ordering. Clobbers Y. sta P8ZP_SCRATCH_W1 sty P8ZP_SCRATCH_W1+1 -_loop ldy #0 - lda (P8ZP_SCRATCH_W1),y + ldy #0 +_loop lda (P8ZP_SCRATCH_W1),y bne + lda (P8ZP_SCRATCH_W2),y bne _return_minusone beq _return -+ lda (P8ZP_SCRATCH_W2),y - sec - sbc (P8ZP_SCRATCH_W1),y - bmi _return_one - bne _return_minusone ++ cmp (P8ZP_SCRATCH_W2),y + bcc _return_minusone + bne _return_one inc P8ZP_SCRATCH_W1 bne + inc P8ZP_SCRATCH_W1+1 @@ -1158,20 +1156,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