!lm12
!rm89
Macro Branch Library...........................................R. F. O'Brien

When I received my copy of the S-C Macro Assembler, my first task was to make up a set of branch macro definitions to use in all my programs.  This set will finally eliminate the need to check usage of BCC, BCS, etc., and generally make the programs more readable.

There are six branch-on-tests:  >BLT, >BLE, >BGE, >BGT, >BEQ, AND >BNE.  All of these would normally be used with two parameters, e.g. >BGT P1,P2...reads: if contents of accumulator is greater than P1 then branch to P2.  The first four of these can be gainfully used with only one parameter, after a comparison.  Sample program:

!lm17
LDA #$8D
CMP #$8E
>BLT THERE ... results in a branch to THERE
!lm12

While >BEQ and >BNE are defined so as to work with only one parameter, there is no reason to so use them - it is easier to just use BEQ and BNE.

The macro >BRA (BRanch Always) is used with one parameter - any others are ignored.  >BRA LABEL causes a jump to LABEL, up to +- 127 bytes away.  To overcome this limitation I decided to put the macro facility to good use to provide for easy branching to any part of a program - this is necessary for writing relocatable code.  I settled for a two-paramter code >JMP:

>JMP P1,P2 ... where P1 is the intermediate or final label you wish to branch to and P2 is the label for this instruction.

Instructions such as the foregoing are inserted anywhere you wish in the program (within 127 bytes of each other) to allow for unlimited branching whilst retaining relocatable code.  The following is an example of how you might use the >JMP code:

!lm17
1000 A    etc.
          (more code....)
2000      >JMP A,B
          (more code....)
3000      >BRA B

!lm12
When a program designed as the above is run it will simulate an absolute jump to A.  The >BRA B will branch to label B, which contains a >BRA A.  This sequence of instructions is transparent to the rest of the program, as the first instruction in the >JMP is to skip around the the >BRA within the definition.

This use of macro definitions can easily be extended to the X and Y registers; simply substitute CPX's or CPY's for the CMP's.

Following are some examples of these macros at work:

!lm17
>BLT #3,THERE....if (A) is less than 3 then go THERE
>BGT $40,THIS....if (A) is greater than ($40) then go THIS
>BEQ #'A,THAT....if (A) is equal to $41 then go THAT
!lm12

To use these macros in all your programs, place the command .IN MACRO.BRANCH.LIBRARY at the beginning of your source program.
