Precedence: Definitions and Macros

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

In building an assembly file (say for ATmega8, by AS6.2 SP1), which one happens first; replacing the defined symbols or the defined macros?

In your opinion, which precedence is more practical?

 

Thank you.

Last Edited: Sun. Mar 1, 2015 - 08:17 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Nothing to do with Studio, moving to other forum.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

In your opinion, which precedence is more practical?

In my opinion?  It doesn't matter.  I don't think I've ever nested pre-processor constructs in AVR assembly, and only rarely in C.

 

First, you should probably say which toolchain you are using ("As6.2" is not a valid answer), and give an example of where it might matter.

 

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.

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

The Atmel Assembler has got C-style preprocessor and after this has completed,  it passes the result to the regular Assembler.

 

The regular Assembler has got ASM-style .MACRO as well as some special .EQU and .DEF style of directives.

 

So you can do quite sophisticated source code with Atmel's Avrasm2 but not as extensive as GNU avr-as.

 

Quite honestly,   you need to provide a lot more information.

Preferably with some real world examples (and your reasons)

 

David.

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

The regular Assembler ...

 Can you expound more on what might be commonly called a "regular" assembler, and which might be irregular?

 

As you mentioned "Atmel assembler" in the first sentence, then that is the irregular one.  So GCC is then the regular one? 

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.

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

Since the current set of assemblers have both preprocessor symbols and macros, AND assembler level symbols and macros, I think you need to be a bit more explicit with your question...

 

The preprocessor stuff (hopefully) happens as pre-processing on text, without any symantic knowledge of assembler-level "symbols."

Assembler macros happen next, and of necessity this includes evaluation of some assembler symbols.  (It's really important, IMO, that assembler macros have access to symbolic information.)  Some symbol resolution can be delayed until link time.

 

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

I am sorry, I thought my question is directly related to AS6.2 SP1, I am using now.

 

Here is a short example:

 

;=======================

 

;====
.DSEG
;====

    .org 0x0060

 

; SRAM

CURampL: .Byte 1 ; 0x60
CURampH: .Byte 1 ; 0x61

CURampU: .Byte 1 ; 0x62

 

;====
.CSEG
;====
 

; registers

.def tmpHiU   = r18 

.def tmpHiH   = r17

.def tmpHiL   = r16

 

; code

    LDS   tmpHiU, CURampU
    LDS   tmpHiH, CURampH
    LDS   tmpHiL, CURampL
 

;=======================

 

In vain, I tried many tricks to let AS6.2 SP1 compile such 3 code lines by using 1-line macro like:

 

; Move 3 consecutive registers in SRAM to General Registers

    MVRSU tmpHiU, CURampU

 

Could you please suggest a 'working' macro, suitable for AS6.2, in this case?

 

Thank you.
 

 

 

 

 

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

my question is directly related to AS6.2 SP1, I am using now.

Ok but the Studio forum is for bugs an other Studio problems etc.

 

Have you read up AVR001 which tells you how the macros work with the Atmel assembler (Regular assembler??)? http://www.atmel.com/images/doc2...

 

They have been around long before AS6.x and should work with the command line assembler without Studio.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

theusch wrote:

The regular Assembler ...

 Can you expound more on what might be commonly called a "regular" assembler, and which might be irregular?

 

As you mentioned "Atmel assembler" in the first sentence, then that is the irregular one.  So GCC is then the regular one? 

 

Since the beginning of time,    manufacturers publish the opcode mnemonics and instruction syntax for their CPUs.  e.g.    LDS r7,1234

I would always regard this as the proper authority.

 

Software houses provide their own directives e.g. .LIST or .EQU

These vary enormously.   e.g. Avrasm2 and gcc-as

 

So I would regard "regular" as opcode statements and "irregular" as directive statements.

 

Yes,   it is not uncommon for Unix cross-assemblers to invent completely different instruction syntax.

Fortunately the usual suspects follow the Atmel syntax.

 

Of course,   this is purely my personal opinion.    The word "regular" is normally used to express people's opinions rather than fact.

 

; Move 3 consecutive registers in SRAM to General Registers

    MVRSU tmpHiU, CURampU

 

I suggest that you use the C preprocessor because it will work with both assemblers.    But this means that you need parentheses e.g. MVxxx(dst, src)

 

Avrasm2 and gcc-as use different syntax for the .MACRO directive.

I also suggest that you change the name:

; Move 3 consecutive registers in SRAM to General Registers
    .MACRO MVRS3
    LDS @0U, @1U
    LDS @0H, @1H
    LDS @0L, @1L
    .ENDM
; invoke with:    
    MVRS3 tmpHi, CURamp

Untested.   If you want to invoke as MVRS3 tmpHi, CURampU then you use @1+0 and @1+1 etc.

 

David.

Last Edited: Mon. Mar 2, 2015 - 08:04 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you, js, for your prompt reply.

 

For instance, I used writing my assembly codes, for ATMEL C51 family, using a text editor and a command-line DOS assembler, as TASM.exe, during the last 20 years (after working with Z80 about 15 years before).

 

So may I ask you in which forum I may find someone who could confirm that, by using AS6.2, a macro for the 3 instructions mentioned in my previous example cannot be done.

But perhaps I am getting old and I missed something while trying to add a macro for these 3 AVR instructions on my rather long AVR macro list ;)

 

I noticed that most AS users prefer C for their projects. So I also understand if my question here sounds irrelevant.

Anyway, ATMEL STUDIO is, to me in the least, a great tool as it is.

 

Edit : I just noticed David's post.

Last Edited: Mon. Mar 2, 2015 - 08:18 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you David for your suggested macro.

I will surely try it.

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

Hello again, David. Your suggested macro worked.

 

I discovered now why I failed doing it after many trials. I was focusing instead on addresses (like using @0-1, @0-2 for example) in order to make the macro a general one (as long the registers have successive addresses and in the same direction; increasing or decreasing).

 

But for my assembly programs, making macros the way you did (using base + suffix) works very well. Thank you.

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

The bad news is that you have to re-write the macros if you move to avr-as.

And most of the other directives need changing too!

 

David.

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

Sorry, David, if my question sounds silly. Is "avr-as" different from the in-built assembler of AS6.2 SP1 I am using now?

 

For instance, all my projects needs one assembly code/file for each one while all of them share the same include files (mainly for macros and more common definitions).

  

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

You can choose avr-as or avrasm2 from AS6.2

 

You are using avrasm2 from Atmel.    It is probably the best choice for simple ASM programs.   And definitely better for debugging.

 

You can .include as many files as you like.    Everything is assembled in one go.

 

GCC's avr-as produces linkable object modules.    Useful when you want mix ASM with C.

 

David.

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

Thank you. I got the picture now.