CARD Math Part 2
In my last post I showed how the Action! compiler produces some pretty optimized code for CARD math under certain circumstances. This time I will show the more general case which should be pretty familiar to anyone who has done 6502 programming.
Here is the Action! program and it’s dis-assembly:
CARD I PROC MAIN() I=2 I=I+2 RETURN
0E6C: .BYTE 00,00 0E6E: 4C 71 0E JMP $0E71 ;I=2 0E71: A0 00 LDY #$00 0E73: 8C 6D 0E STY $0E6D 0E76: A9 02 LDA #$02 0E78: 8D 6C 0E STA $0E6C ;I=I+2 0E7B: 18 CLC 0E7C: AD 6C 0E LDA $0E6C 0E7F: 69 02 ADC #$02 0E81: 8D 6C 0E STA $0E6C 0E84: AD 6D 0E LDA $0E6D 0E87: 69 00 ADC #$00 0E89: 8D 6D 0E STA $0E6D 0E8C: 60 RTS
Most of what is here we have discussed before so I won’t go into great detail. As you can see since I is initialized to the value 2 the INY optimization can’t be used so two loads and stores are performed. It’s interesting to note that a different register is used for each byte. I am not sure why the compiler chooses to do this, although in the end it doesn’t affect program size or performance.
The add part of the program is standard 6502 16-bit math, adding the lower byte, then adding the upper byte which also handles and carry from the lower byte.
0 Comments
Recommended Comments
There are no comments to display.