Arduino inline assembler guide?

Is there an inline assembler guide for Arduino?

I did find reference to some in the playground and forum, but unfortunately all the useful sounding external links were broken. >:(
Most of the others just seemed to be using NOP as an accurate sub microsec delay.

At the moment all I want to do is turn PB0 on and off, but I can’t put PORTB in the asm command, it refuses to compile as if it doesn’t know what it is.

#include <stdint.h>
#include <avr/io.h>

void setup() {
  DDRB |= bit(0);  

void loop()
//  bitWrite(PORTB,0,1); // this works
  asm("sbi PORTB,0 \n\t"); // this won't compile
//  bitWrite(PORTB,0,0); // this works
  asm("cbi PORTB,0 \n\t"); // this won't compile

Why don't you just use direct port manipulation commands ? ( ), I would bet the compiler converts it to the same minimum number of instructions that ASM code could.


I knew someone would say that!

What I want to do will be far more involved than the example I gave. That was just to illustrate the problem I was having.

Anyway, with reference to the wayback machine, I managed to find an old version of the page that was always being linked to, and work out how I had to code what I wanted. I have yet to find a live new version of the page.

The code I now have is: (IOBIT is the bit I want 0-7).

  asm("sbi %0,%1" : : "I" (_SFR_IO_ADDR(PORTB)) , "I" (IOBIT) );
  asm("cbi %0,%1" : : "I" (_SFR_IO_ADDR(PORTB)) , "I" (IOBIT) );

And yes, I just did some test with my logic analyser (just for you), and yes, the following code translate to exactly the same frequency, approx 2Mhz (running on ATtiny 8Mhz internal clock), which translates to 2 clocks for both CBI and SBI.

  bitSet(PORTB, IOBIT);
  bitClear(PORTB, IOBIT);

I have yet to find a live new version of the page.

It seems to have grown an extra underscore:

Develop your web-searching skills! If a link like "" doesn't work, chop off the end of the url and see if "" is still around...