error "Invalid register"

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

Hi all. I have a problem with AVR Studio 4 not compiling my code. It gives me an "invalid register" error for every line of code in my asm-file. The situation is as following;

I started an assembler project for ATmega16 in AVR Studio 4. I wrote my code, set the platform and device options and stated these two lines at the very beginning of my asm-file;

.include "m16def.inc"
.device ATmega16

Is this not sufficient for AVR Studio?

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

How about posting just a few more lines - such as a few of the ones that actually generated the error?

Cliff

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

except for some .def-lines following the .include and .device, these are the first lines of the file

.cseg
.org 0x60

boot_reset:
sei

ldi SPH, 0x04
ldi SPL, 0x5f

sbr MCUCR, 0
sbr MCUCR, 1

/mario

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

You cannot use ldi with a register like SPH. The usual way to set that is to ldi the value (0x04) into a temporary AVR register (like R24 perhaps?) then use out to write this to SPL.

So try something like:

ldi r24, 0x04
out SPH, r24
ldi r24, 0x5F
out SPL, r24

It may be worth a look at www.avrbeginners.net to learn some of this stuff.

Cliff

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

....and you should really start .cseg at address zero - so delete your .org statement

...and don't use literal constants when there are appropriate .equ statements alreday in the .inc file. So it should be

ldi r24, high(RAMEND)
out SPH, r24
ldi r24, low(RAMEND)
out SPL, r24

...and the .device directive is deprecated in AVRASM2, so you can delete that as well

:P :P

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

thank you both for your help, I'm extremely grateful.

/mario