BigEd wrote:
Brilliant! A big step forward for 6502 on ARM!
Thanks Ed, I'm sure there is still considerable room for improvement.
I'm not convinced my conversion from 26-bit ARM to 32-bit ARM was optimal.
Here's an example, the CPY instruction, where the value of the V flag need to be preserved.
The old 26-bit code was:
Code:
// Opcode C0 - CPY #$00
3cf0: e4da0001 ldrb r0, [sl], #1
3cf4: e1a0200f mov r2, pc
3cf8: e1580c00 cmp r8, r0, lsl #24
3cfc: e022200f eor r2, r2, pc
3d00: e2022201 and r2, r2, #268435456 ; 0x10000000
3d04: e132f00f teqp r2, pc
// Fetch next
3d08: e4da0001 ldrb r0, [sl], #1
3d0c: e08cf300 add pc, ip, r0, lsl #6
The new 32-bit code is:
Code:
// Opcode C0 - CPY #$00
.align I_ALIGN
opcode_C0:
ldrb r0, [sl], #1
mrs r2, CPSR
and r2, r2, #V_FLAG
cmp r8, r0, lsl #24
mrs r1, CPSR
bic r1, r1, #V_FLAG
orr r1, r1, r2
msr CPSR_flg, r1
FETCH_NEXT
So two additional instructions.
I must admit, I struggled to understand how the original code was working. It only makes sense if TEQP r2, pc toggles the appropriate flag bit. I couldn't find a good description of this behaviour in any documentation though.
Can anyone come up with a more efficient pattern?
Dave