Warning of redefining a register

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

I have ATmega8 and I write its codes in assembly only using AS6.2 SP1.

 

I agree that, in case a register is redefined, the warning is useful in general; it was discussed here years ago.

 

But, as you know, there are always exceptions to the rule ;)

For example, in some projects, redefining a register with different names when it is used as a temporary one in different functions (called exclusively) lets the source code be clearer (without extra comments); mainly if there are many of such register.

 

So I thought that perhaps an option to disable this warning (in a project) was included in recent versions. By searching so far, I couldn’t find this option but perhaps I missed it.

 

Thank you.

 

This topic has a solution.

Last Edited: Mon. Oct 16, 2017 - 09:47 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

KerimF wrote:
redefining a register with different names when it is used as a temporary one in different functions lets the source code be clearer

I disagree - that sounds like a Really Bad Idea.

 

Surely, by obfuscating the fact that you are sharing the same register, you just increase the risk of this causing problems!

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

awneil wrote:

 

I disagree - that sounds like a Really Bad Idea.

 

Surely, by obfuscating the fact that you are sharing the same register, you just increase the risk of this causing problems!

Yes, in general, it is a really bad idea as you mentioned.

 

But after designing tens of controllers in which it was better, for me in the least ;) , redefining my temporary registers with different names, I just liked to know if it is possible for me to get rid of tens of warning lines (about redefining) that separate me from the error lines :) during syntax debugging.

 

So I hoped that someone here can 'confirm' that the option doesn't exist. After all, I became familiar with this warning :)

 

  

 

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

You first need to tell which assembler you are referring to.  Is it Atmel's AVRASM2?  Or GCC GAS?

 

Are you speaking of fragments like this?

AVRASM ver. 2.1.30  C:\OptiCode\HY148\List\HY148p.asm Wed Sep 27 16:07:24 2017

C:\OptiCode\HY148\List\HY148p.asm(1101): warning: Register r2 already defined by the .DEF directive
C:\OptiCode\HY148\List\HY148p.asm(1102): warning: Register r3 already defined by the .DEF directive
C:\OptiCode\HY148\List\HY148p.asm(1103): warning: Register r5 already defined by the .DEF directive
C:\OptiCode\HY148\List\HY148p.asm(1104): warning: Register r4 already defined by the .DEF directive
C:\OptiCode\HY148\List\HY148p.asm(1105): warning: Register r7 already defined by the .DEF directive
                 

 

...where the offending lines might be

;NAME DEFINITIONS FOR GLOBAL VARIABLES ALLOCATED TO REGISTERS
    .DEF _worknum=R2
    .DEF _worknum_msb=R3
    .DEF _state=R5
    .DEF _line_dirty=R4
    .DEF _item=R7

 

Now, the above are excerpts from the .ASM produced by the CodeVision C compiler.  The "offending" lines correspond to global register variables.  The redefinition allows the ASM source to refer to those register variables by name.

 

[As further background, CV .DEFs all the GP registers thus creating the conflicts...

    .DEF R0X0=R0
    .DEF R0X1=R1
    .DEF R0X2=R2
    .DEF R0X3=R3
    .DEF R0X4=R4
    .DEF R0X5=R5
    .DEF R0X6=R6
    .DEF R0X7=R7
    .DEF R0X8=R8
    .DEF R0X9=R9
    .DEF R0XA=R10

...

When I've done ASM apps, I remember redefining  some registers to give more meaningful names in different sections of the program.

 

If the above is your situation, I wouldn't find those warnings to be a "bad thing".  It would alert you when you >>do<< give registers different names.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Last Edited: Thu. Sep 28, 2017 - 03:01 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:

You first need to tell which assembler you are referring to.  Is it Atmel's AVRASM2?  Or GCC GAS?

 

If the above is your situation, I wouldn't find those warnings to be a "bad thing".  It would alert you when you >>do<< give registers different names.

 

I am sorry for not being clearer when I started my OP with "I have ATmega8 and I write its codes in assembly only using AS6.2 SP1".

I should remember that the assembler I am using is AVRASM2.

 

I agree that this warning is surely not a bad thing. I just wished I can disable it whenever necessary. So it was just a wish that won't be the first or the last one that cannot be made real.

 

 

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

Greg Muth

Portland, OR, US

Atmel Studio 7.0 on Windows 10

Xplained/Pro/Mini Boards mostly