*
*
*               BRANCH INSTRUCTIONS
*
*
RAMStart        EQU     $0040
RomStart        EQU     $E000
ResetVector     EQU     $FFFE

                ORG     ResetVector
                FDB     MAIN

                ORG     RAMStart
HIGH            FCB     $0A
LOW             FCB     $01
EQUAL           FCB     $05

                ORG     RomStart

MAIN            LDA     EQUAL      ; Load A with $05
                LDX     EQUAL      ; Load X with $05

*
*               ALL BRANCHING INSTRUCTIONS USE RELATIVE ADDRESSING
*               CONDITIONAL BRANCH INSTRUCTIONS TEST THE CONDITION CODE BITS
*

                CMP LOW
                BCC LABEL1         ; Branch if Carry Bit Clear
                NOP

LABEL1          ADD #$FF
                BCS LABEL2         ; Branch if Carry Bit Set (Same as BLO)
                NOP
                
LABEL2          LDA EQUAL
                CMP EQUAL
                BEQ LABEL3         ; Branch if Equal 
                NOP

LABEL3          CMP LOW
                BGE LABEL4         ; Branch if Greater Than or Equal To (Signed Operands)
                NOP

LABEL4          CMP LOW
                BGT LABEL5         ; Branch if Greater Than (Signed Operands)
                NOP

LABEL5          ADD  #$01
                BHCC LABEL6        ; Branch if Half Carry Bit Clear
                NOP

LABEL6          ADD  #0F
                BHCS LABEL7        ; Branch if Half Carry Bit Set 
                NOP
                
LABEL7          LDA EQUAL
                CMP LOW
                BHI LABEL8         ; Branch if Higher
                NOP

LABEL8          CMP EQUAL
                BHS LABEL9         ; Branch if Higher or Same (Same as BCC)
                NOP

                ; Input IRQ 1 from status window
LABEL9          NOP
                BIH LABEL10        ; Branch if IRQ Pin High
                NOP

                ; Input IRQ 0 from status window
LABEL10         NOP
                BIL LABEL11        ; Branch if IRQ Pin Low
                NOP

LABEL11         CMP HIGH
                BLE LABEL12        ; Branch if Less Than or Equal To (Signed Operands)
                NOP

LABEL12         CMP HIGH                
                BLO LABEL13        ; Branch if Lower (Same as BCS)
                NOP

LABEL13         CMP EQUAL
                BLS LABEL14        ; Branch if Lower or Same
                NOP

LABEL14         CMP HIGH
                BLT LABEL15        ; Branch if Less Than (Signed Operands)
                NOP

LABEL15         CLI
                BMC LABEL16        ; Branch if Interrupt Mask Clear
                NOP

LABEL16         ORA #$FF
                BMI LABEL17        ; Branch if Minus
                NOP
                LDA EQUAL

LABEL17         SEI                ; Set interrupt mask
                BMS LABEL18        ; Branch if Interrupt Mask Set
                NOP

LABEL18         CMP HIGH
                BNE LABEL19        ; Branch if Not Equal
                NOP

LABEL19         LDA #$7F
                BPL LABEL20        ; Branch if Plus
                NOP

LABEL20         BRA LABEL21        ; Branch Always
                NOP
                
LABEL21         BRN LABEL20        ; Branch never
                NOP
                LDA EQUAL
                
                ; HIGH = $0A = %00001010
                
                BRCLR 2,HIGH,LABEL22     ; Branch if Bit n in M Clear
                NOP
                
LABEL22         BRSET 3,HIGH,LABEL24     ; Branch if Bit n in M Set
                NOP
                
LABEL24         CBEQ EQUAL,LABEL25       ; Compare and Branch if Equal
                NOP
                
LABEL25         DBNZ HIGH,LABEL26        ; Decrement and Branch if Not Zero
                NOP
                
LABEL26         DBNZA LABEL27            ; Decrement and Branch if Not Zero
                NOP

LABEL27         DBNZX LABEL28            ; Decrement and Branch if Not Zero
                NOP
                
LABEL28         JMP   LABEL29            ; Jump (Not relative); PC <-- Jump address
                NOP

LABEL29         NOP
                NOP
                
                
                
                
                
    
