Tag Archives: MIPS

My 2 bits on 8-Bits

*image comes from Arduino.CC website, official Arduino Website
*image comes from Arduino.CC website, official Arduino Website

Arduino Uno is equipped with an Atmel 8-bit AVR RISC-based microcontroller -> 8 bits equals 1 byte -> that means it does everything one byte at a time…. ONE BYTE!!!!!!!!!!!!!!!!

– the ‘int’ type is 2 bytes – that means at least 2 actions per ‘int’ operation??

– the ‘long’ type is 4 bytes – that means at least 4 actions per ‘long’ operation??

I’m using ‘long’ type for timing and for encoder counters. A lot of the functions I’m using operates on sets of 4-byte operands. Whatever math I decide to do on the encoder interrupt counter…. would it scale up because I’m using more bits? Maybe not….

Enter… THE DATASHEET!! 

Apparently the ATmega328 is a lot more capable than I assumed. From what I’ve read, it’s RISC, but it supports pipelining. They call it MIPS, “microprocessor without interlocked pipeline stages”. According to the datasheet, the atmega can execute multiple instructions within one clock cycle, instruction operations in near parallel, depending on the operations. It does so by loading instructions, fetching data and loading registers, and executing operations that are not dependent on each other’s outputs. It doesn’t execute just one instruction per clock cycle as I previously thought. It think the datasheet said it can support as many as 16 pipelines. This ensures that each module of the microprocessor wastes the least amount of time doing nothing while waiting for certain operations to finish. This totally solves everything. Even if it electronically takes longer to load ‘long’ type than ‘int’ type, it might not be enough where I should be worrying about things slowing down. And, it’s doing stuff in parallel. How bad can it get?

Btw, if you read further along, the datasheet details interrupt handling and behavior : all interrupts are processed, by priority if received simultaneously, and at least 1 line of main code is executed between each interrupt process.

(Also, the datasheet is 450 pages long.)

But they don’t tell you any of this when you’re writing your first Arduino program, or when you’re learning to code in C, or learning to code in general. C is the generic pseudo-instruction language for computers. Everything underneath the hood is designed by computer engineers specifically for the instruction set type, whose design is incorporated into the microchip architecture. This allows you to write in C and not need to know the specifics about the chip’s architecture as long as the compiler can handle it. But it pays to know.

Moral of the story: don’t assume. It makes a [thing] out of [things].

* * *

To be Continued…

-david