16 bit compare routine

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

16 bit compare routine

580 次查看
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 回复数

427 次查看
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 项奖励

427 次查看
bigmac
Specialist III

Hello,

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

Regards,

Mac

0 项奖励