Invalid register (SBIW)

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

I have an ATtiny 85 and i wrote this:

.set D3 = 0x08

	ldi r16, 0x05
	ldi r17, 0x01
	rcall delay
	rjmp PC

delay:
	sbiw r17:r16, 1
	brcc delay
	ret

and i get an error on SBIW, "Invalid register", any idea how to fix this?

Last Edited: Sat. Dec 9, 2017 - 08:30 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

SBIW - Subtract Immediate from Word

Description:

Subtracts an immediate value (0-63) from a register pair and places the result in the register pair. This instruction operates on the upper four register pairs, and is well suited for operations on the pointer registers.

 

As you can see from the instruction description, the register pair you want to use is out of range for this instruction.

 

edit: so to answer your question, you need:

 

delay:
    subi r16, 1
    sbci r17, 0
    brcc delay
    ret
Last Edited: Sat. Dec 9, 2017 - 08:51 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks, i fixed it with sbiw r25:r24, 1