Starting with AVR assembly

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

Hi all.

What is needed to create a basic assembly program in Atmel Studio 6? I have created an assembly code project but the page is blank and I don't really know what to write. What is the template for creating a new application?

 

I've seen suggestions like ".include m328blabla" but they seemed unnecessary since the m328p is already specified during the creation of the project. ".CSEG and .ORIG 0000" or something was something else I saw.

 

My biggest problem by far is just getting on with stuff, once I get the jist of them I can do it. I've programmed in assembly before, I'm not a total noob but when it comes to AVR asm I am. I've looked for good sources etc and I'm sure there are many but that's kind of the problem. I just want to hear some good advice from the mouth of a real person and you are the closest I can think of.

So shoot!

sol i sinne - brun inne

Last Edited: Thu. Jun 15, 2017 - 08:08 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

When you specify a target in the IDE, that only drives the processor definition file tree. You still have to include the tree. In C, you need to #include <avr/io.h> or something close to that. When I did assembler work back with Studio 4, I remember having to include a  processor-specific definition file. Don't know how that works, now, in assembler.

 

But, my point is that simply defining the target in the IDE is not sufficient. You certainly need to do that, but there is more.

 

Jim

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

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

Thanks for the heads up. I guess that's my first line, yay! *edit, oh, seems it was unnecessary after all in AS6

sol i sinne - brun inne

Last Edited: Thu. Jun 15, 2017 - 08:22 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I remember having to include a  processor-specific definition file.

Not necessary with AS6 or 7, they hold your hand by including the .inc file when you start a project. (I always delete their include file and add my own with .nolist and .list so that I don't get a huge .lss file).

 

This is the STK500 demo program.

;***** STK500 LEDS and SWITCH demonstration 
.nolist
;.include "8515def.inc" 
.include "m32def.inc" 
.list

.def Temp =r16 ; Temporary register 
.def Delay =r17 ; Delay variable 1 
.def Delay2 =r18 ; Delay variable 2 

.dseg
test_label:	.byte 1

.cseg
;***** Initialization 
RESET: 
   ser   Temp 
   out   DDRB,Temp      ; Set PORTB to output 
;**** Test input/output 
LOOP: 
   out   PORTB,temp      ; Update LEDS 
   sbis   PIND,0x00      ; If (Port D, pin0 == 0) 
   inc   Temp         ; then count LEDS one down 
   sbis   PIND,0x01      ; If (Port D, pin1 == 0) 
   dec   Temp         ; then count LEDS one up 
   sbis   PIND,0x02      ; If (Port D, pin2 == 0) 
   ror   Temp         ; then rotate LEDS one right 
   sbis   PIND,0x03      ; If (Port D, pin3 == 0) 
   rol   Temp         ; then rotate LEDS one left 
   sbis   PIND,0x04      ; If (Port D, pin4 == 0) 
   com   Temp         ; then invert all LEDS 
   sbis   PIND,0x05      ; If (Port D, pin5 == 0) 
   neg   Temp         ; then invert all LEDS and add 1 
   sbis   PIND,0x06      ; If (Port D, pin6 == 0) 
   swap   Temp         ; then swap nibbles of LEDS 

	push	temp
	lds		temp,test_label
	subi	temp,-1
	sts		test_label,temp
	pop		temp

   ;**** Now wait a while to make LED changes visible. 
   DLY: 
   dec   Delay 
   brne   DLY 
   dec   Delay2 
   brne   DLY 
   rjmp   LOOP         ; Repeat loop forever 

 

 

 

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

Thanks to both of you. Is a branch in the end of the program a must? What happens if the AVR reaches the last line of code and it's not a branch backwards? Is it the same as a "NOP" or can the instruction memory be old garbage and therefore do nothing or something weird? So many questions...

sol i sinne - brun inne

Last Edited: Thu. Jun 15, 2017 - 08:27 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is a branch in the end of the program a must?

What do you think will happen? After all you say wink

I've programmed in assembly before, I'm not a total noob

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

Haha okay, in my defense there are many levels of noobness blush

sol i sinne - brun inne

Last Edited: Thu. Jun 15, 2017 - 08:33 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There is no OS to exit to. If your program runs off the "end", anything  is possible.

 

That endless loop is a critical part of every program I've  done, either asm or c.

 

Jim

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

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

With out an endless loop on the end, the cpu will continue to pick up the next instruction and do Whatever it says to do, even something you did not want it to do.

So, you need to create some kind of endless loop.   It could include a sleep command, but you still need to loop back in case it wakes up again.

 

Jim

 

 

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

One good thing is that you can run the code in the simulator and SEE what happens, even better if you have a real chip and a debugger.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

So thus far;

An endless loop sooner or later in the program, just like we do when writing in C for the AVR. Gotcha.

 

Hm yes the simulator. I think I tried to use it but something was wrong. Does it come installed from the get go or do I need to add anything to Atmel Studion 6?

sol i sinne - brun inne

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

. Does it come installed from the get go

Yes for most chips. The M328 should be supported.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

What is needed to create a basic assembly program in Atmel Studio 6?

 

First decide which assembler to use:  There is one that is compatible with C (you might add parts written in C in the future) and one that's not.
 

avrfreaks does not support Opera. Profile inactive.

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

If you go for the one that's not compatible with the C compiler, it's often called "Atmel assembler" or some such. And your learning experience start here: http://www.avrbeginners.net .

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

Last Edited: Fri. Jun 16, 2017 - 02:19 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

SprinterSB wrote:
First decide which assembler to use: There is one that is compatible with C (you might add parts written in C in the future) and one that's not.
JohanEkdahl wrote:
If you go for the one that's not compatible with the C compiler, it's often called "Atmel assembler" or some such.

Why don't you guys just come out and say it?  There is Atmel assembler, and also a flavor that is part of the GCC package.  [re-word or clarify or correct as you like]

 

But I think you need to stop short of saying "not compatible with C".  For example, my CodeVisionAVR C apps use the Atmel assembler.  And Atmel assembler fragments are easily integrated.

 

 

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

Yes Lee. I was only trying to keep my answer simple, since the OP is clearly a beginner.

Side fun: when I was starting to type "answer" and had come to "an" the tablet keyboard software suggested "ankle" and "anxiety".. :-)

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

I lost my flow a bit when the simulator didn't work. Maybe I should download AS7 and hope it works there. Which assembler is used in AS?

sol i sinne - brun inne

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

You get a choice of 2 assemblers in AS7. One is the same Atmel Asm2 as found in AS4 and one is GNU as which is the assembler for the C and C++ compilers.

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

clawson wrote:
One is the same Atmel Asm2 as found in AS4 and one is GNU as which is the assembler for the C and C++ compilers.

Gee, it would be nice if someone had mentioned that earlier in the thread.

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

I'm using a phone, didn't read the preceding - just responding to the most recent comment.