Tag Archives: avr

Arduino Inline Assembly Tutorial (Branching)

Loop and Branch Branching is a fundamental feature of computers. For example, branching allows a computer to repeat instruction sequences. One of the most  basic forms of repetition is a “loop”, and the loop is probably the most widely used … Continue reading

Posted in Uncategorized | Tagged , , , , , | 2 Comments

Towards a More General digitalRead

The arduino digitalRead function is a nice bit of code. However, it takes more than a cursory glance to determine exactly how it performs (see Yak Shaving). It also compiles into approximately 222 bytes of code, and its slow in … Continue reading

Posted in Uncategorized | Tagged , , , , , , | Leave a comment

Arduino Inline Assembly Tutorial (Math)

Increment, Decrement, Add and Subtract INC is a mnemonic for INCrement. INC adds one to the contents of the register placing the result back into the register. The C flag in the Status Register (SREG) is not affected by the … Continue reading

Posted in Uncategorized | Tagged , , , , , | Leave a comment

Arduino Inline Assembly Tutorial (Bit Shifts)

Introduction In this tutorial we continue our examination of bit operations. Specifically we discuss left and right shifts. We’ll end this tutorial with an assortment of short C language MACRO code segments that demonstrate checking bits. Shift to Multiply The … Continue reading

Posted in Uncategorized | Tagged , , , , , | 1 Comment

Arduino Inline Assembly Tutorial (Bit Ops)

Introduction Bit operations are the foundation upon which all microcontroller programming builds. A good understanding of bit functions is essential for efficient arduino programming in general, and specifically for inline assembly programming. Its that simple. It really is simple too. … Continue reading

Posted in Uncategorized | Tagged , , , , , | 3 Comments

Arduino µC Status Register (SREG)

Like all microcontrollers the arduino’s AVR µC has a flag register to indicate various conditions. The Status Register is referred to in short as the “SREG”, and can be directly referenced inline using __SREG__. It is an 8-bit wide register, … Continue reading

Posted in Uncategorized | Tagged , , , , , | Leave a comment

Arduino Inline Assembly Tutorial (Ports & Pins)

Mapping Memory The 3 basic types of memory in the arduino were discussed in tutorial #1. Again, here we are interested in SRAM data memory, which the arduino uses as memory-mapped IO. MMIO means that a part of the SRAM … Continue reading

Posted in Uncategorized | Tagged , , , , , | Leave a comment

Arduino Inline Assembly Tutorial #4 (Constraints)

Introduction I have a confession to make. My previous examples were not very efficient assembly code. That might seem like an odd comment, especially since my typical example used just 2-4 lines of code. But, these examples were coded as … Continue reading

Posted in Uncategorized | Tagged , , , , , | 6 Comments

Arduino Inline Assembly Tutorial #3 (Clobbers)

Clobbered Guess what? Our previous tutorial example (Tutorial #2) has a problem. Here is the inline portion of that code: Notice in our example, we use register #26, or r26. Even though we only used this register temporarily, we have … Continue reading

Posted in Uncategorized | Tagged , , , , , , | Leave a comment

Arduino Inline Assembly Tutorial #2 (Extending asm)

The Extended asm Statement The first tutorial in this series can be found here and covers a great amount of necessary background material. The general form of an extended inline assembler statement is: asm(“code” : output operand list : input … Continue reading

Posted in Uncategorized | Tagged , , , , , | 2 Comments