How to program Arduino without C?

Just pondering how this might be done. I'd be keen to learn to do simple stuff just in assembler, for the heck of it.

How does one do that?

(What prompted this was a visit to my local supplier today. I asked how business is and he said a few unis and colleges are buying through him and Arduino is used as a learning platform. But he said at least one doesn't want the students to use the IDE, for whatever reason. (One reason I can think of is to prevent lifting of code from the playground, the forum etc..... ))

Where would I start to investigate programming Arduino at a low-level?

The IDE provides a text editor and some icons that cause the compiler and, optionally, avrdude to be used to compile the code and upload it to the Arduino.

You can use any editor, and create batch files to execute the compiler and avrdude commands.

But why? A sketch is a sketch. Using the IDE or not using it won't change that simple fact.

Sorry didn't make myself clear Paul. I meant to program without even using C++ as the platform but in assembler.

Purely as an academic exercise I might add.

Using/not using the IDE and using C/C++ or not using C/C++ are two completely different things.

You can use the IDE and program in assembler. Not that I have any idea how. I learned how to do stuff in assembler a long time ago. I've forgotten all that stuff, since C++ is so much easier to use.

Perhaps you should change your post title.

PaulS:
Perhaps you should change your post title.

Yep, good point.

But even writing the code in assembler you must "compile it" (attention to the quote mark). You need to create the hex file to transfer to the atmega. Don't you?

The Atmel '328P data sheet has lots of examples for programming in assembler.
Example, writing to EEPROM in assembly:

EEPROM_write:
; Wait for completion of previous write
sbic EECR,EEPE
rjmp EEPROM_write
; Set up address (r18:r17) in address register
out EEARH, r18
out EEARL, r17
; Write data (r16) to Data Register
out EEDR,r16
; Write logical one to EEMPE
sbi EECR,EEMPE
; Start eeprom write by setting EEPE
sbi EECR,EEPE
ret

vs C:

void EEPROM_write(unsigned int uiAddress, unsigned char ucData)
{
/* Wait for completion of previous write */
while(EECR & (1<<EEPE))
;
/* Set up address and Data Registers */
EEAR = uiAddress;
EEDR = ucData;
/* Write logical one to EEMPE */
EECR |= (1<<EEMPE);
/* Start eeprom write by setting EEPE */
EECR |= (1<<EEPE);
}

You need an include at the top of the sketch, something like
#include<asm.h>
I'd have to look at some code I did 6-8 months ago to see what the actual call is.
Code still needs to be compiled, true.
That's what AVR GCC does, and avrdude.
http://gcc.gnu.org/
Arduino IDE ties it all together nicely for us.
Can always write the code in Notepad++ if one doesn't want to use the IDE.

luisilva:
But even writing the code in assembler you must "compile it" (attention to the quote mark). You need to create the hex file to transfer to the atmega. Don't you?

Yes and it's the creation of the file to upload I'm asking about, and a description of the process.

Decades ago I had an MPF-1 for programming the Z80 in assembler: wondering how to do that kind of thing for an Arduino.

Do this help?

http://www.avr-asm-tutorial.net/avr_en/

EDIT: BTW, I believe that the application described in the pdf is this.

The only time I use assembler is to force a no-op as part of fast SPI transfers:

spdr = dataArray[0]; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;
spdr = dataArray[1]; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;
spdr = dataArray[2]; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;
spdr = dataArray[3]; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;

So instead of waiting for SPI.transfer to get an interrupt to indicate a byte has finished transferring out, it basically just times out the transfer.
Can send out data at nearly 8 Mbit/s this way, just over 1uS/byte. I think I confirmed 17 clocks per byte when I looked at with a logic analyzer. 45 bytes in 47uS. Turned off interrupts before the transfer to keep micros() from interfering.

This guy here:

uses Atmel studio:

I've found Atmel Studio to be really slow to start up when I used it on "older" computers (4-5 year old Sony Viao).
Have not tried reloading it in my new multicore Lenovo with i7 core & lots of memory.

Good stuff here on Atmel Studio

It does way more than just make the GCC toolchain run nice behind the scenes and support 3-4 chip types (Atmega8, 168, 328, 1280, 2560, 8U2, 16U2, 32U4, and others that user/developers have come up with, like the Attiny series and 644/1284P).
Supporting the entire Atmel family and all the tools is probably what extends the startup time so much (seemed like minutes long).
Also uses the Jungo driver for the Atmel AVR ISP MKii, while the IDE uses Libusb-Win32 Driver.

JimboZA:
But he said at least one doesn't want the students to use the IDE, for whatever reason.

Maybe it's because of the peculiar mucking-about that the Arduino does behind the scenes to translate your Arduino sketch to proper C++ before it compiles it. Perhaps the view is that people are better of learning how to code standard C++ instead of the Arduino-specific not-quite-C++ that the Arduino IDE requires. Lots of employers would find C++ programming experience valuable, and it will immediately translate to many different environments, but if you learned your programming skills in Arduino then you'll be picking up habits that will trip you up when you try to write proper C++.

Given the Arduino's goal (as I understand it) of making firmware development more accessible to novices, it puzzles me that the Arduino developers took the decision not to use standard C++.

Given the Arduino's goal (as I understand it) of making firmware development more accessible to novices, it puzzles me that the Arduino developers took the decision not to use standard C++.

Well I think, you over state the differences. The arduino IDE supplies the main() function to wrap your startup and loop function around and adds an init function to start timer0 for the millis() function, so not really depriving the user of much to be concerned about when moving to a different platform, at least in my opinion. I believe it's even possible to create your own main() function which will override the supplied on if one wishes, although I've never tried that. But to be clear the programming language used with arduino IDE is gcc C/C++ pure and simple, to say otherwise is pure FUD.

Yep, not whole lot in main:

#include <Arduino.h>

int main(void)
{
	init();

#if defined(USBCON)
	USBDevice.attach();
#endif
	
	setup();
    
	for (;;) {
		loop();
		if (serialEventRun) serialEventRun();
	}
        
	return 0;
}

Just ensures that setup is called once, and then loop indefinitely.
And whatever init() does, like setting up timer0 for basic timing functionality as Lefty says.
I see init.c, init.h, init.tcl in the IDE files, not sure which does what.

It's not 'C++ pure and simple'. The IDE automatically adds some #include files to your code, and decides what files to compile and link based on what headers you included, and puts the header files it thinks you need where it thinks you need them, and then inserts a bunch of prototype statements that will be right in some cases but wrong in others. None of this is standard C++. If you think this is how you write C++ then you are going to be really confused when you move to a more conventional development environment that compiles the code you wrote as-is and follows the conventions for include file naming and paths and so on.

It's pretty similar to C++, but the differences are significant.

PeterH:
It's not 'C++ pure and simple'. The IDE automatically adds some #include files to your code, and decides what files to compile and link based on what headers you included, and puts the header files it thinks you need where it thinks you need them, and then inserts a bunch of prototype statements that will be right in some cases but wrong in others. None of this is standard C++. If you think this is how you write C++ then you are going to be really confused when you move to a more conventional development environment that compiles the code you wrote as-is and follows the conventions for include file naming and paths and so on.

It's pretty similar to C++, but the differences are significant.

Again FUD in my opinion. Are any of those things that the arduino IDE does not written in pure C++ ? The language used is either C++ or it is not. The things done by the pre-processor do not deviate or violate the fundemental C++ language standards. Your concerns/problems are something other then what programming language is being used, perhaps you could recast your concerns?

But to be clear the programming language used with arduino IDE is gcc C/C++ pure and simple, to say otherwise is pure FUD.

Try writing a C program that looks like an Arduino sketch, adding ONLY a main() that calls init(), setup(), and loop() in an infinite loop. It won't compile. The IDE does more than provide a main() if one is not defined.

It adds header files and defines function prototypes, to name a couple of things that it does (poorly, in some cases).

PaulS:

But to be clear the programming language used with arduino IDE is gcc C/C++ pure and simple, to say otherwise is pure FUD.

Try writing a C program that looks like an Arduino sketch, adding ONLY a main() that calls init(), setup(), and loop() in an infinite loop. It won't compile. The IDE does more than provide a main() if one is not defined.

It adds header files and defines function prototypes, to name a couple of things that it does (poorly, in some cases).

But does that mean the arduino programming language being used is not C++ ?

To say the arduino programming environment is different then some more mainstream environments is one thing, but to say the arduino is not programmed in C++ in a different statement, no?