16 bit compare routine

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

16 bit compare routine

547 Views
paul_1951
Contributor I

Hi,

 

I have looked but could not find any assembly code for a 16 bit compare routine. We are using a QG4 part and I need to determine if a 16 bit value is =, <,or >.

there is an 8 bit routine but not sure if can be modified for 16 bits.

 

Thanks in advance for any help.

Labels (1)
0 Kudos
2 Replies

394 Views
tonyp
Senior Contributor II

The LDHX, CPHX solution is good only for 16-bit, and assumes 9S08 if SP-indexed, and certainly it can not be used with X-indexed operands.

More generic 16-bit (or higher) compares can be done for any addressing mode by using the Accumulator (A) in a series of LDA/CMP/BNE instructions, (the final BNE being redundant), starting from the MSB, like so:

op1  rmb 2

op2 rmb 2

...

  lda op1

  cmp op2

  bne Skip

  lda op1+1

cmp op2+1

;;;;; bne Skip

Skip

; here we can use all comparison branches available, just like after a single CMP instruction.

This method can be turned into a generic macro or subroutine that compares any two 16-bit (or higher) operands regardless of addressing mode.  (Care has to be taken when the macro is allowed to compare against immediate mode values to use the related syntax for those cases.)

(Many such macros are available for ASM8 here)

0 Kudos

394 Views
bigmac
Specialist III

Hello,

H:X is a 16-bit register.  Try using the instructions LDHX and CPHX.

Regards,

Mac

0 Kudos