6

I started out just want to play with my granddaughter when I bought the kit, but now that I am reading the datasheet of ATmega328, I want to get deeper and I want to try some assembly coding just to play around. I have no idea whether this kit can even support it.

This is the kit.

If this cannot do assembly, what do I need to buy to do that? What IDE do I need?

JRE
  • 71,321
  • 10
  • 107
  • 188
Alan0354
  • 77
  • 5
  • https://wokwi.com/projects/290809734244598280 – jsotola Aug 02 '23 at 06:38
  • 1
    You can do simulation with just a software download. If you want 'bare metal' programming you need a programmer (not expensive). If you want to do debugging with a hardware breakpoint (just one on that chip), it's more expensive (and you might consider a more powerful chip). Which do you want to do? – Spehro Pefhany Aug 02 '23 at 11:12
  • Claims to be 100% compatible with Arduino. Search for Arduino development tools. It also claims: Added tutorial for building development environment under Ubuntu. You might find the learning curve for a new development environment frustrating (I do). For learning assembler, a single-step simulator is very useful - I find that debugging a long program is possible after many simulation sessions. – glen_geek Aug 02 '23 at 12:54

4 Answers4

9

You can use assembly language on any microcontroller. The real question is "What IDE can I use?"

Strictly speaking, you don't need an IDE at all. A simple text editor, a command line assembler, and a tool to transfer the binary is all you need. An IDE makes it easier but isn't required.

The Arduino IDE includes everything you need to transfer the binary to the microcontroller. From what I've read, it also includes everything you need to use assembly language.

According to this thread on the Arduino forum, it is relatively easy to use assembly language with the Arduino IDE.

Summary:

  1. Start a project and save it. This will generate the .ino file and the folder it belongs in.
  2. Add a tab to the project (little "down arrow" far to the right of the tab showing the project tab.)
  3. Name the new file "test.S" where "test" is whatever name you want to use. The file extension must be "S" and it must be upper case.
  4. Add assembly code to the .S file.
  5. Call the assembly code from the .ino file.

You can define a subroutine in assembly like this:

.global example

example: ;assembly code goes here.

You would call it from the .ino file like this:

extern "C" {
  // function prototype
  void example();
}

void loop() { example(); }

I haven't tried it, so I can't tell you how well it works or what difficulties may arise.

Check out the link and follow the directions there - I've only posted a quick summary that doesn't include many of the details from the Arduino forum thread.


I expect that at least one downside to that is that there'll be some code from the Arduino libraries included in your binary. That will restrict you somewhat in the size of your assembly code.

Another thing is that the Arduino system requires a bootloader installed on the microcontroller. That occupies space in the microcontroller's flash space, again limiting how much space your own code can occupy.

For fiddling around and learning, you should have plenty of space. If you were going to produce a product to sell then the requirement of the Arduino bootloader and the space it occupies might be a problem.

JRE
  • 71,321
  • 10
  • 107
  • 188
5

Programming in Assembly has nothing to do with hardware. It depends on the toolchain you're using. The MCU doesn't care if the machine code it executes was created by writing in hex editor, a compiler or an assembler as long as it's valid code.

The kit you linked to is essentially an Ardunio Uno. Typically you would use the Arduino IDE to program an Uno. The IDE includes the AVR-GCC compiler which supports Assembly, however, the editor doesn't (except for inline assembly). This means while you could compile a project with Assembly code, it's not as easy as clicking the compile button and then use another button to upload the code. Instead you would have to compile from command line and use AVRDUDE (which also comes with the Arduino IDE) to upload the generated code. Edit: You can use external Assembly files in an Arduino Project, see JRE's answer.

As mentioned in the answer by atom, you could also use the MPLAB X IDE. It supports writing code in Assembly directly in the IDE, but you still have to use AVRDUDE to manually upload the code to the Uno. If you want to upload the code directly, you would have to buy proper debugging hardware that is compatible with AVR like a Pickit or Atmel ICE.

nanash1
  • 4,464
  • 5
  • 29
1

The arduino tools can do inline assembly, which means you can just drop some assembly code into your arduino program. This is likely to be the easiest way for you to start playing with AVR assembly, since you don't need any extra tools or setup other than the plain old arduino IDE. Basically you will end up with something like this:

volatile byte a=0;

void setup() { Serial.begin(9600);

asm ( "ldi r26, 42 \n" //load register r26 with 42 "sts (a), r26 \n" //store r26 into memory location of variable a );

Serial.print("a = "); Serial.println(a); }

void loop() { }

I just grabbed this example from this page: https://ucexperiment.wordpress.com/2016/03/07/arduino-inline-assembly-tutorial-2/

which seems to be a decent reference to get you up and running, including how to get values into and out of your assembly routine. This sort of thing is pretty useful if you have some short routines in which you need tight control of timing, like if you're trying to bit-bash video signals or something. You can implement most of your logic in C and just drop a few lines of ASM in there for the critical parts.

Tom
  • 11
  • 1
0

You can program ATMEGA 328. Use MPLab IDE. You can code in both C and assembly.

atom
  • 1
  • 1