*
*
*               COMPARE INSTRUCTIONS
*
*
RAMStart        EQU     $0040
RomStart        EQU     $E000
ResetVector     EQU     $FFFE

                ORG     ResetVector
                FDB     MAIN

                ORG     RAMStart
MEM1            FCB     $FF
MEM2            FCB     $15

                ORG     RomStart

MAIN            LDA     #$FF          ; Load A to $FF
                CMP     MEM1          ; Compare A with MEM1 (Compute A-M)
                CMP     MEM2          ; Compare A with MEM3
                CMP     #$FF          ; Comapre A with immediate value FF

                LDA     #$15          ; Load A with $15
                LDHX    #$0001        ; Indexed, 8-bit offset
                CMP     $40,X         ; Compare A with MEM2 (loc. 40+1)

                LDX     #$FF
                CPX     MEM1          ; Compare X with MEM1 (Compute A-X)
                CPX     MEM2          ; Compare X with MEM3
                CPX     #$FF          ; Comapre X with immediate value FF

                LDHX    #$FF15        ; Load $FF15 to H:X
                CPHX    MEM1          ; Compare H:X with MEM1:MEM1+1

                NOP

*
*               IF PORTA ($00) IS LESS THAN OR EQUAL TO LIMIT VALUE ($7F)
*               THEN SET PORTB($01) EQUAL TO 1 ELSE 2
*

                LDA     #$00
                STA     $04           ; SET DDRA ($04) AS INPUT
                LDA     #$FF
                STA     $05           ; SET DDRB ($05) AS OUTPUT

*
*               The INPUTA command sets the simulated inputs to port A.
*               The CPU reads this input value when port A is set as an input port.
*               Type INPUTA $0F at the status window
*
                LDA     #$7F          ; Set limit value
                CMP     $00           ; Read and compare with PORTA
                BHI     HIGH          ; Go to HIGH if value is higher
                LDA     #$01          ; LESS, so set A = 1
                BRA     SAVE          ; Go to SAVE
HIGH            LDA     #$02          ; HIGH, so set A = 2
SAVE            STA     $01           ; Save A in PORTB

                NOP


*
*               SET MEMORY LOCATIONS STARTING AT $0040
*               ENDING AT $01FF WITH $FF
*

                LDA     #$FF
                STA     $0040          ; SET 00 AT $0040

                LDHX    #$0041         ; Let H:X point to first location
LOOP            MOV     $0040,X+       ; Move value of $0040 to memory, increment H:X
                CPHX    #$01FF         ; Compare H:X with upper limit
                BLS     LOOP            ; Go to LOOP if lower or same

DONE            BRA     DONE           ; DONE, STAY HERE (BRANCH TO SELF)


*
*               CLEAR MEMORY LOCATIONS STARTING AT $0040
*               ENDING AT $01FF
*


                LDHX    #$0040         ; Let H:X point to first location
LOOP1           CLR     ,X             ; Clear memory pointed by  H:X
                AIX     #$01           ; Increment pointer to next location
                CPHX    #$01FF         ; Compare H:X with upper limit
                BNE     LOOP1          ; Go to LOOP if lower or same

DONE1           BRA     DONE1          ; DONE, STAY HERE (BRACH TO SELF)


*
*               TEST INSTRUCTIONS (TEST FOR NEGATIVE OR ZERO)
*               SETS THE N AND Z CONDITION CODES
*
                CLRA                    ; Set A with $00
                STA     $0040           ; Set ($0040) with 00

                LDA     #$F1
                LDX     #$10

                TSTA                    ; (A) - $00
                TSTX                    ; (X) - $00
                TST     $0040           ; ($0040) - $00

                NOP

*
*
*               INCREMENT AND DECREMENT INSTRUCTIONS
*
*

                CLRA                    ; Set A with $00
                CLRX                    ; Set X with $00
                CLR     $0040           ; Set $0040 with $00

                INCA                    ; Increment A
                INCA
                DECA                    ; Decrement A

                INCX                    ; Increment X
                DECX                    ; Decrement X
                DECX
                DECX

                INC     $0040           ; Inrement memory location $0040
                DEC     $0040           ; Decrement memory location $0040
                DEC     $0040
                DEC     $0040

*
*               ADD IMMEDIATE
*
                AIX     #$05            ; Add immediate to H:X register
                AIS     #$01            ; Add immediate to SP register

                NOP

*
*
*               BCD ADDITION
*               46 + 27 = 73
*
                LDA     #$46            ; Load BCD number 46
                ADD     #$27            ; Add BCD number 27
                DAA                     ; Decimal Adjust Accumulator

                NOP

*
*
*               NEGATE  (TWO'S COMPLEMENT)
*
*

                CLRA
                CLRX
                CLR     $0040           ; Set $0040 with $00


                DECA
                NEGA

                INCX
                INCX
                NEGX

                NEG     $0040

                NOP



