Question: What registers do I use to access the IO on the Arduino Uno when I am using assembly for programming?

Background: I was interested in practicing my assembly language skills on the Arduino (I thought it would be easier to turn LEDs on/off than to worry about console IO). From doing a preliminary search, I have found that the AVR toolchain can be used to program the Arduino. Yet, I don't quite know how to find the corresponding registers for the IO pins.

2 Answers 2


The datasheets for the AVR microcontrollers are reasonably good to read. Just Google for the exact controller on your Arduino (eg. ATmege328) and find the "Complete" datasheet on the atmel.com website. Don't download the "Summary", it doesn't include a lot of information. Download the datasheet from atmel.com, that is the only location with the most recent documentation.

There are three registers used in basic IO (check the chapter called "I/O-Ports"):

Where n is a port identifier, a letter ranging from A, B, C, ... depending on the number of IO pins your controller has. Each bit in each register represents a single GPIO pin (yes, you need some basic knowledge on binary to fully understand this).

  • DDRn, Data Direction Register: This basically configures a pin for either input (0) or output (1).
  • PORTn, Port n Data Register: When a pin is set as output, the related bit toggles the output pin high (1) or low (0). When configured as input, this enables a weak pull up resistor on the output pin.
  • PINn, Port n Input Register: Use this register to read the current level on a pin that is configured as input.
  • 3
    This. Step 1: Stop thinking of it as an arduino. It's not. It's a ATmega MCU on a PCB. 2. Read the datasheet. 3. No really, read the datasheet. Feb 12, 2014 at 6:46
  • Ah... that is exactly what I needed. I think I spent so much time looking for Arduino-targeted tutorials, that I forgot I was simply programming an AVR controller, and could use its datasheet.
    – apnorton
    Feb 12, 2014 at 13:00

Check this out: http://arduino.cc/en/Reference/PortManipulation

Also: http://arduino.cc/en/Hacking/PinMapping168

As for other ports and pins, check put the datasheet for your controller, they're really useful to people who can understand them! :)

  • 3
    Link only answers are not useful for the site, as we are not trying to establish a repository of links. Moreover, link only answer are useless if the link ever goes down in the future. It would be better to summarize or paraphrase the content within the answer itself so that users can find what they need here itself or at the very least gain sufficient context so as to be able to find solutions themselves.
    – asheeshr
    Feb 12, 2014 at 4:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.