KitsAndParts.Com Forum

A place to exchange information about parts and kits supplied by http://kitsandparts.com

You are not logged in.

#1 2010-07-23 11:15:45

WA5BDU
Member
From: Russellville, AR
Registered: 2010-07-12
Posts: 14
Website

General question on register use

Is there something about the ATmega88P or the way we are using it such that registers r0 through r15 are not valid?  I attempted to add a new definition for r15 and kept getting "invalid register" errors when building the file.  Finally switched to a register higher than r15 and all seems to be OK.  What's the deal?

The offending line is -

cpi r15, 100

I tried both using its internal name, as above, and by using a defined name as in

.def temp7 =r15

cpi temp7, 100

with no luck in either case

Nick

Last edited by WA5BDU (2010-07-24 14:03:14)

Offline

 

#2 2010-07-23 12:07:04

ak2b
Administrator
From: New York City
Registered: 2008-08-12
Posts: 364

Re: General question on register use

Hi Nick,

Funny, I had the same problem just last week.
You will find the answer here.

Tom, ak2b


**I have yet to figure out how to use a variable like a register when the upper registers get used up.

Offline

 

#3 2010-07-23 21:54:09

WA5BDU
Member
From: Russellville, AR
Registered: 2010-07-12
Posts: 14
Website

Re: General question on register use

Thanks Tom, that's just what I needed. A set of opcodes won't work on r0 through r15!  I did a bunch of programming on the Butterfly without realizing that. OTOH, the register usage had already been set up by Steve Weber, so I was protected.

Offline

 

#4 2010-07-24 07:53:31

ak2b
Administrator
From: New York City
Registered: 2008-08-12
Posts: 364

Re: General question on register use

Hi Nick,

This problem came up for me when I thought I would write a menu section. I added a switch with the idea in mind that when the switch was pressed it would put you in menu mode. To indicate menu mode I wanted to put a 1 in a variable to so that the encoder routine could test this bit and jump elswhere to scroll menu items instead of change frequency.  In Diz's code all registers r16 and above are used so I figured I would use one of the lower ones. ...and that's where I ran into this problem. In Steve's code he actually uses a lot of the lower registers and leaves some of the upper ones unused. In some cases the lower registers are  defined twice smile.
.def    dd4    =r4
.def    dd5    =r5
.def    fbin0    =r4
.def    fbin1    =r5
This just points out that I have a lot to learn. I will get past it, though.
I've also been messing around with the Butterfly DDS these past few weeks which is one of the reasons for not working on this menu problem. I have both programs loaded into AVR Studio at the same time and often make comparisons between the two. Even though KD1JV is using the AD9851 the idea is the same and it is interesting and educational to see how the same problem is resolved in two different sets of code. Between Diz and Steve I've learned a great deal. The effort to learn assembler is lessened a lot when the subject is so interesting.

Tom, ak2b

Offline

 

#5 2010-07-24 09:51:16

WA5BDU
Member
From: Russellville, AR
Registered: 2010-07-12
Posts: 14
Website

Re: General question on register use

Yep, I was doing pretty much the exact same thing, except instead of a new switch I'm monitoring for a "long press" (1 s) of the knob.  Short presses still advance the step size but a long press will take you to a band change mode where rotating the knob cycles you through the ham bands and another press selects one.

My changes to the KD1JV Butterfly code are here -

http://pages.suddenlink.net/wa5bdu/butterfly_dds.html

Those redefinitions or multiple definitions don't hurt anything and can help clarity in different contexts as long as you remember that they exist and watch out for conflicts between routines using the same resisters under different names.

I'm currently going back to study the AD9834 data sheet ... I told myself that it's programmed "pretty much" like the AD9850 and AD9851, but now I think there are some significant differences I need to get a grip on.

Nick, WA5BDU

Offline

 

#6 2010-07-24 10:08:17

wa2mze
Member
From: South Florida
Registered: 2009-08-22
Posts: 172

Re: General question on register use

This may be one of the reasons I program the AVR's in "C".  There is a misconception that C produces bloated code and that you can get better performance and smaller code with assembler than with a higher level language.  It is true that the code produced by most compilers is rigid in its' call frame structure which does add some overhead to function calls.  If you write in assembler you probably don't store function local variables on the stack frame which DOES save you some access overhead and results in a smaller binary.  Also the default C runtime libraries can add to the code size, but you can force the linker to omit them if not needed.  Even tiny AVR's such as the tiny13A can be programed in C and the code fits nicely.

BTW I do use assembler where it makes sense.  Some micro's are just NOT suited for higher level languages.  The PIC12 and PIC16 series are a good example of a processor that is not very suitable for higher level languages (there ARE C compilers for the PIC16's but they are not very good IMHO.  The PIC18's are another story....). 

I suppose that a good assembler programmer could fit an application into a processor where it would be tight or impossible with a HLL.  But in such a case it would still make sense to look for a micro with a larger code space because there wouldn't be much room left for future enhancements.   

The WinAvr package contains a decent C compiler based on Gnu GCC.  It works seamlessly with Avrstudio.

Offline

 

#7 2010-07-25 04:52:49

w8bh
Member
From: Dayton, OH
Registered: 2010-05-24
Posts: 38

Re: General question on register use

WA5BDU wrote:

Yep, I was doing pretty much the exact same thing, except instead of a new switch I'm monitoring for a "long press" (1 s) of the knob.  Short presses still advance the step size but a long press will take you to a band change mode where rotating the knob cycles you through the ham bands and another press selects one.

Nick,
I posted some code similar to what you want to do. 
Please take a look at http://w8bh.net/avr/AddMemories.pdf

- Bruce

Offline

 

Board footer

Powered by FluxBB