Re: My Favorite Instruction of 2023 / 2024
Posted: Sun Nov 17, 2024 7:44 am
The Commodore Vic 20 Forum
https://www.sleepingelephant.com/~sleeping/ipw-web/bulletin/bb/
https://www.sleepingelephant.com/~sleeping/ipw-web/bulletin/bb/viewtopic.php?t=10825
Using (ZP,X) with X<>0 comes around with reserving a larger part of the ZP as data stack and using X as data stack pointer. Especially ($00,X) can be used to work on memory data with a set of pointers contained in said data stack. INC ZP,X and DEC ZP,X are available to conveniently increment or decrement these pointers - $00,X and $01,X address the respective low- and high-byte of the pointers. Other offsets can be used to probe deeper into parameter lists: as indirect-ZP wraps, the "base address" actually works as signed byte offset on the data stack pointer in X!pixel wrote:I second this.
Code: Select all
CLC
LDA src :ADC size :STA src
STA src+1:ADC size+1:STA src+1
CLC
LDA dst :ADC size :STA dst
STA dst+1:ADC size+1:STA dst+1
Code: Select all
[...]
LDX #src:JSR Adjust
LDX #dst:JSR Adjust
[...]
.Adjust
CLC
LDA $00,X
ADC size
STA $00,X
LDA $01,X
ADC size+1
STA $01,X
RTS
Code: Select all
.2417 B5 FD LDA $FD,X
.2419 D5 F9 CMP $F9,X
.241B F0 09 BEQ $2426
.241D 08 PHP
.241E B0 03 BCS $2423
.2420 F6 FD INC $FD,X
>2422 2C
.2423 D6 FD DEC $FD,X
.2425 28 PLP
.2426 60 RTS
https://github.com/SvenMichaelKlose/tun ... src/lib/zp
One instruction shorter:pixel wrote:Code: Select all
.proc zpw_dec_x dec 0,x lda 0,x cmp #$ff bne :+ dec 1,x : rts .endproc
Code: Select all
.proc zpw_dec_x
lda 0,x
bne :+
dec 1,x
: dec 0,x
rts
.endproc
m)Mike wrote: ↑Sun Nov 17, 2024 8:40 am One instruction shorter:Code: Select all
.proc zpw_dec_x lda 0,x bne :+ dec 1,x : dec 0,x rts .endproc
![]()