ASM FOR ATMEL STUDIO 7 ¡¡¡¡¡¡

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
GREETINGS FRIENDS, FOR DAYS I'M TRYING TO BE ABLE TO USE THE MACRO _SFR_IO_ADDR

WITHOUT RESULT. TO BE ABLE TO USE ASM AND C LANGUAGE AT THE SAME TIME I HAVE TO MODIFY OR ADD IN ORDER TO BE ABLE TO USE THE MACRO _SFR_IO_ADDR _SFR_IO_ADDR FOR THE COMPILER TO RECOGNIZE IT. REGARDS.

jhordy

Last Edited: Wed. Mar 25, 2020 - 09:17 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What on earth have you done to that formatting?!

 

surprise

 

jhordy wrote:
TO BE ABLE TO USE ASM AND C LANGUAGE AT THE SAME TIME

Have you seen this:  https://www.nongnu.org/avr-libc/user-manual/group__asmdemo.html ?

 

EDIT

 

Also do a search of the forum - it has been discussed before:

 

https://www.avrfreaks.net/search/site/mix%2520c%2520assembler?filter_by=9631&so=0

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Wed. Mar 25, 2020 - 08:28 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My ears are ringing!

Letting the smoke out since 1978

 

 

 

 

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

Ears? My eyeballs are spinning around and around.

 

Just show us an example of what you have tried and describe how the result is different from what is expected! You have written nothing that is helpful for any person who tries to answer your question.

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

Last Edited: Wed. Mar 25, 2020 - 01:46 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've tried to correct the silly font in post #1 but it won't change the inter-line spacing. Anyway...

 

@OP, if you read:

 

https://www.nongnu.org/avr-libc/user-manual/assembler.html

 

and follow the link to:

 

https://www.nongnu.org/avr-libc/user-manual/group__avr__sfr__notes.html

 

you will learn the __SFR_OFFSET trick. Now it does say:

This automatically subtracts 0x20 from I/O space addresses, but it's a hack,

but personally I don't agree with the manual. For my money it is not a "hack" it is the very best way to use <avr/io.h> in GNU as .S files and makes the code much cleaner.

 

Now instead of:

#include <avr/io.h>

    .section .text
    
    .global main
main:
    ldi R16, 0xFF
    out _SFR_IO_ADDR(DDRB), R16
loop:
    in R17, _SFR_IO_ADDR(PORTB)
    eor R17, R16
    out _SFR_IO_ADDR(PORTB), R17
    rjmp loop

you can write the much "cleaner" code:

#define __SFR_OFFSET 0
#include <avr/io.h>

    .section .text
    
    .global main
main:
    ldi R16, 0xFF
    out DDRB, R16
loop:
    in R17, PORTB
    eor R17, R16
    out PORTB, R17
    rjmp loop

which, to me anyway, seems like a very nice "hack" indeed !!

 

Your mileage may vary.

 

PS I do wonder why you are using the GNU assembler and not the the Atmel one. Or is this really about interworking C/C++ and Asm ?

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

hello my friend, thanks for taking the time sorry for the grammar at the beginning it turns out that I am not so good in English and I just copied and pasted for which I apologize, it turns out that if my intention to merge the c and asm language, plow a good time and tried to maximize a routine that I have beyond what the c language allows for much shorter times, with that I do not want to create a program that only uses asm but the function of my interest can be more efficient in the times, I found a text where he informed me that it was possible to use c and asm language routines together in atmel studio, and at the point of understanding the language and instructions, but I came across certain MACROS, which I did not understand and that is why I put my doubt (_SFR_IO_ADDR), as I understand so far the use of the assembly language with C is possible and atmel allows it according to and seen examples.

I leave a couple of links, down there if you may not explain very well what I'm trying to learn more.

 

https://gcc.gnu.org/onlinedocs/g...

 

https://www.ibiblio.org/gferg/ld...

 

I will be publishing a code that I am trying to compile, regarding an example of a rgb leds strips ws2812b it turns out that when using only c language, the times are not in the required margins and I have problems when assigning the color to each led, since each one needs a pulse in certain parameters, for a logical 1 0.8 us, and for a logical 0.4 us. 

jhordy