Thank you, everyone, for your comments.
This code is a portion of the handler for the IF keyword in TSC Micro BASIC Plus. I have discussed other aspects of the project in these other threads:
viewtopic.php?f=2&t=7988viewtopic.php?f=2&t=7990Proxy wrote:
this is exactly why i'd recommend (atleast on the 65xx) to use the Carry Flag instead of N/Z for single bit return values of functions.
because the Carry flag only gets modifed by a handful of instructions, so you can safely move around data or even do some logic operations without having to worry about it getting messed up.
Good idea, but that alone does not get around the pla flags problem.
BB8 wrote:
I would avoid the stack: a STA temp /.../ LDA temp, or - if .Y is available - a TAY /.../ TYA.
Do you have room for that?
I have no room in the zero page to spare. The original 6800 code used up the entire direct page. Quite the contrary, I have to move things out. The prime candidate is the 78 bytes to hold the values of the 26 variables.
Saving register A in Y or X is the cat's meow in this case.
The paraphrasing process starts one subroutine at a time, rationalizing that there will be time for optimization later.
It turns out that CLSREL offers much opportunity for improvement.
Code:
01260 * CLASSIFY RELATIONAL OPERATION
01261
091F 81 3B [2] 01262 CLSREL CMPA #$3B
0921 23 06 (0929) [4] 01263 BLS CLSRE5
0923 81 3E [2] 01264 CMPA #$3E CHECK CHAR
0925 22 02 (0929) [4] 01265 BHI CLSRE5
0927 5F [2] 01266 CLRB CLEAR FLAG
0928 39 [5] 01267 RTS RETURN
0929 5C [2] 01268 CLSRE5 INCB SET FLAG
092A 39 [5] 01269 RTS RETURN
It can easily be changed to return status in the carry flag; doing that means not having to clobber register B:
Code:
01260 * CLASSIFY RELATIONAL OPERATION
01261
091F 81 3B [2] 01262 CLSREL CMPA #'<'
0921 23 06 (0929) [4] 01263 blo CLSRE5
0923 81 3E [2] 01264 CMPA #'>'+1 CHECK CHAR
0925 22 02 (0929) [4] 01265 bhs CLSRE5
0928 39 [5] 01267 RTS RETURN with carry flag set
0929 5C [2] 01268 CLSRE5 clc Clear carry flag
092A 39 [5] 01269 RTS RETURN
allowing the calling code sequence to be modified:
Code:
08BE 36 [4] 01211 tab SAVE A
08BF A6 01 [5] 01212 LDAA 1,X GET CHAR
08C1 8D 5C (091F) [8] 01213 BSR CLSREL REL OP?
08C3 32 [4] 01214 tba RESTORE A
08C4 26 04 (08CA) [4] 01215 bcc IF1
08C8 1B [2] 01217 add 1,X FORM REL CODE
08C9 08 [4] 01218 INX ; Skip a second character
08CA 08 [4] 01219 IF1 INX
Note that instead of pushing the first character onto the stack, it could simply be reloaded from 0,X and there is no need to reload the second character into register B before adding it to register A.