Invalid Register (in my case register Z)

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

Hey. I'm working on indirect addressing. Actually
I'm trying to clear some of "working registers", -> (R0-R29)

This is the code:

#include "m16def.inc"


clr ZL
clr ZH

Loop:
	st ZH,Z
	inc ZL
	cpi ZL,30
	brne Loop
 

I get an error on the line:
"st ZH,Z" and it says invalid register.

I'm using AVR studio 4, for ATmega16 8-bit microcontroller.

So my question is why I get this error, how to avoid this error, so basically what I am doing wrong.

One additional question even it's not for this topic.
I am working in AVR studio 4 editor, but I would like to see the numbers of my lines on the left side. Is that possible and If It is, how to turn it on.

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

The destination operand stands on the left side and the source operand on the ricght.

avrfreaks does not support Opera. Profile inactive.

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

You are storing the whole 16 bit Z value into the memory location pointed to by the high byte of Z. But, the st operation needs the full 16 bit pointer contained in Z as the pointer, not just one half of the word. Further, you cannot store a 16 bit value in an 8-bit SRAM location.

Odds are that you have ZH and Z in the wrong order.

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

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

Thank you both, I have to say that I am positive suprised of the "answer speed"

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

using same registers (ZH,Z) as source and destination might bite you.
Assembler datasheet seem to imply that the result is only undefined if the source is pre-decremented or post-incremented.
But I would not risk to use it at all.
Suddenly you add a + or - to the instruction and spend half a day figuring out why the stored variables are wrong.

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

Another thing is that even if you had the registers set up correctly you want to write 0x00 30 times?

Also, as Jim noted it appears you are trying to load a 16bit address in an 8 bit register. FWIW, the ST command usually means to store in SRAM, therefore you will need to load the Z register with either the beginning of the SRAM or define the number of bytes you are writing to. In this case it appears to be 30 bytes:

so what you would want to see is:
.dseg
storage_area: .byte 30

ldi  ZH,HIGH(storage_area)
ldi  ZL,LOW(storage_area)
clr  r17
Loop:
   clr  r16
    st  z+,r16    ;stores 0x00 in SRAM location z increment z register
   inc  r17
   cpi  r17,0x1E  ;check to see if 30 bytes have been stored
   brne  loop
end:  rjmp  end

This will load thirty bytes in SRAM with 0x00 starting at sram location "storage_area"

Note: the .dseg is part of the code, my bad. :oops

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

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

Thank You, It's really much more than I was looking for.