[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Stack Pointer Problem on 65816
On Tue, 17 Jun 2003 16:42:27 +0000, Kent Dickey wrote:
<code snipped>
> This code is good, but since $fded also saves the X register, we can
> save the intermediate value in X rather than on the stack (saves cycles
> but not bytes).
Apparently the OP was originally planning on using X to index
successive screen locations and avoid $fded altogether.
> By using shifts more carefully, we can also avoid all
> but the main loop branch.
This is really nice.
> This is getting ridiculously optimized
> and I know no one works on such a minor piece of code so much.
Only for fun.
> prstatus
> php
> pla ; get status in a
> ldy #7
> loop asl ;sets carry if high bit was 1
> tax ;save in X register
> lda #$58 ;$b0 / 2
> rol ;shift in carry, now it is $b0 or $b1
> jsr $fded
> txa ;copy X back to acc
> dey
> bpl loop
> rts
>
> I bet a byte or two can be saved from this as well, especially
> if 65c02 or 65816 instructions are used.
prstatus
php
pla ;get P in A
ldy #$58 ;$b0 / 2
sec
rol ;shift high bit into C and set a sentinel
loop tax ;save status in X
tya
rol ;build digit ($b0 or $b1) in A
jsr $fded
txa
asl ;shift the next bit into C
bne loop ;when sentinel is gone, we're done
rts
The length is the same, but it takes 12 cycles fewer, assuming
I've counted correctly.
Sheldon