Page 2 of 2

Re: comparing 16 bit numbers

Posted: Sun Feb 27, 2022 11:19 pm
by barrym95838
It looks correct at first glance, but only for unsigned numbers.

Re: comparing 16 bit numbers

Posted: Mon Feb 28, 2022 8:01 am
by speculatrix
barrym95838 wrote:
It looks correct at first glance, but only for unsigned numbers.
Thanks.

I should have said that this is for unsigned numbers.

Re: comparing 16 bit numbers

Posted: Sat Jan 13, 2024 12:23 am
by pebmeister
Just as an FYI I have made these macros that work with my assembler, but they should be compatible to others



Code: Select all

;********************************************
;*                                          *
;*  BEQ16                                   *
;*                                          *
;*  16bit beq                               *
;*                                          *
;*  \1  a       16-bit                      *
;*  \2  b       16 bit                      *
;*  \3  Destination a = b                   *
;*                                          *
;*  destroys    a                           *
;*                                          *
;********************************************
        .macro BEQ16
        lda \1 + 1
        cmp \2 + 1
        bne @exit
        lda \1
        cmp \2
        beq \3
  @exit
        .endm

;********************************************
;*                                          *
;*  BNE16                                   *
;*                                          *
;*  16bit beq                               *
;*                                          *
;*  \1  a       16-bit                      *
;*  \2  b       16 bit                      *
;*  \3  Destination a != b                  *
;*                                          *
;*  destroys    a                           *
;*                                          *
;********************************************
        .macro BNE16
        lda \1 + 1
        cmp \2 + 1
        bne \3
        lda \1
        cmp \2
        bne \3
        .endm

;********************************************
;*                                          *
;*  BLT16                                   *
;*                                          *
;*  16bit bcc                               *
;*                                          *
;*  \1  a       16-bit                      *
;*  \2  b       16 bit                      *
;*  \3  Destination a < b                   *
;*                                          *
;*  destroys    a                           *
;*                                          *
;********************************************
        .macro BLT16
        lda \1 + 1
        cmp \2 + 1
        bcc \3
        bne @exit
        lda \1
        cmp \2
        bcc \3
@exit
        .endm

;********************************************
;*                                          *
;*  BLE16                                   *
;*                                          *
;*  16bit branch less than or equal         *
;*                                          *
;*  \1  a       16-bit                      *
;*  \2  b       16 bit                      *
;*  \3  Destination a <= b                  *
;*                                          *
;*  destroys    a                           *
;*                                          *
;********************************************
        .macro BLE16
        lda \1 + 1
        cmp \2 + 1
        bcc \3
        bne @exit
        lda \1
        cmp \2
        bcc \3
        beq \3
@exit
        .endm