I am porting the Rankin and Wozniak 32 bit floating point code from Doctor Dobbs (posted here:
http://www.6502.org/source/floats/wozfp1.txt) to the Ophis assembler. Reading the code is a head trip because the code flow is a bit convoluted to save space. There are two weird things that I would normally think were bugs if a mere mortal wrote it But given the origin and age of the code, they might actually do something useful.
I was curious if anyone had experience with them.
• The exp function contains an ADC at address 1E29 that doesn’t seem to do anything useful because there’s an LDA M1 directly afterwards.
Code:
1E26 18 CLC CLEAR CARRY FOR ADD
1E27 A5 0A LDA M1+1
1E29 69 78 ADC =120 ADD 120 TO INT
1E2B A5 09 LDA M1
1E2D 69 00 ADC =0
1E2F 10 0B BPL CONTIN IF RESULT POSITIVE CONTINUE
Is there some side effect that is being exploited?
• The swap function contains a STY at 1F1E without an LDY prior.
Code:
1F1C A2 04 SWAP LDX =$04 INDEX FOR 4-BYTE SWAP.
1F1E 94 0B SWAP1 STY E-1,X
1F20 B5 07 LDA X1-1,X SWAP A BYTE OF EXP/MANT1 WITH
1F22 B4 03 LDY X2-1,X EXP/MANT2 AND LEAVEA COPY OF
1F24 94 07 STY X1-1,X MANT1 IN E(3BYTES). E+3 USED.
1F26 95 03 STA X2-1,X
1F28 CA DEX ADVANCE INDEX TO NEXT BYTE
1F29 D0 F3 BNE SWAP1 LOOP UNTIL DONE.
1F2B 60 RTS
I suspect that the first pass through the loop moves a junk byte, but all the rest of the iterations do something useful, so the junk byte is overwritten on the final iteration.