16 bit compare routine

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

16 bit compare routine

473件の閲覧回数
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.

ラベル(1)
0 件の賞賛
2 返答(返信)

320件の閲覧回数
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 件の賞賛

320件の閲覧回数
bigmac
Specialist III

Hello,

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

Regards,

Mac

0 件の賞賛