compare two registers in assembly

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi guys,
I am using assembly.
I want to compare two registers, one being twice the value it is currently (multiplied by two) without changing any of the values of either register.

i.e.

cp ZL,(XL*2)
breq....

is it possible without changing the value of XL even temporarily?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No, you need to take a copy and double that then use in the compare.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yes that is what I was afraid of, thanks.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you don't want to do the double (LSL = ADD RnRn) at this point perhaps you can keep a "shadow" of XL and add 2 to that each time you increment XL? This moves the "overhead" to another place in the code which *might* help.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

here is what I did, it works.

	lds	R10,TempH		;load high byte from ram	
	mov	R7,R10
	lsl	R7			;multipy by two

	lds	r11,TempL		;load low byte from ram
	mov	R8,r11
	lsl	R8			;multipy by two

the compare happens later down the road. There may be a more efficient way to do this, but it works for me. Thanks clawson for your quick response!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This way you are comparing BOTH values multiplied by 2 - why not then just compare the original values instead?

Warning: Grumpy Old Chuff. Reading this post may severely damage your mental health.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Maybe he's comparing 16 bit values, and he isn't doing a carry between the high and low bytes?