Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9180973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:10:43+00:00 2026-06-17T18:10:43+00:00

Hi StackOverflow community, I am trying to program my old Arduino Duemilanove Board (Atmega

  • 0

Hi StackOverflow community,

I am trying to program my old Arduino Duemilanove Board (Atmega 168V-10PU) in Assembler. I tried it a few times before but everytime the code was not executed. So i tried to program an equivalent test program in C, and it worked. Here it is:

// file led.c
#include <avr/io.h>

int main(void)
{

    DDRB = 0xFF;
    PORTB = 0xFF;

    while (1) {
        asm("nop\n");
    }

    return 0;
}

The asm dump of the compiler results in (shortened),

ldi r24,lo8(-1)  ;  tmp44,
out 0x4,r24  ;  MEM[(volatile uint8_t *)36B], tmp44
out 0x5,r24  ;  MEM[(volatile uint8_t *)37B], tmp44

which works and activates the LED at Arduino Pin 13 (AVR pin PB5).

But when I use this asm file,

// file led.S
#include "avr/io.h"

.global main

main:
    ldi r24, 0xFF
    out DDRB, r24
    out PORTB, r24

 end:
    jmp end

the compiler dump results in (shortened),

ldi r24, 0xFF
out ((0x04) + 0x20), r24
out ((0x05) + 0x20), r24

what might explain why nothing happens.

In addition here are the makefiles for the C version and the Assembler version

Thanks for helping!

EDIT: Here are also the full assembler dump files of the C version and the Assembler version

EDIT 2: I looked up the register addresses in the include file iom168.h, which references to iomx8.h, where it says #define PORTB _SFR_IO8 (0x05). The compiler follows the include chain

io.h -> iom168.h -> iomx8.h
io.h -> common.h -> sfr_defs.h

In sfr_defs.h is written:

#define _SFR_IO8(io_addr) ((io_addr) + __SFR_OFFSET)

A few more lines upwards the offset is defined:

#ifndef __SFR_OFFSET
/* Define as 0 before including this file for compatibility with old asm
sources that don't subtract __SFR_OFFSET from symbolic I/O addresses.  */
#  if __AVR_ARCH__ >= 100
#    define __SFR_OFFSET 0x00
#  else
#    define __SFR_OFFSET 0x20
#  endif
#endif

(Sorry for the formatting)
Any idea where this error comes from?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T18:10:44+00:00Added an answer on June 17, 2026 at 6:10 pm

    You should use the helper macros _SFR_IO_ADDR() and _SFR_MEM_ADDR() to access SFRs using i/o and memory instructions, respectively, because they have different addresses in the two namespaces. The default is apparently memory mapped, but don’t count on it.

    As such your code could look like:

    #include "avr/io.h"
    
    .global main
    
    main:
        ldi r24, 0xFF
        out _SFR_IO_ADDR(DDRB), r24
        out _SFR_IO_ADDR(PORTB), r24
    
     end:
        jmp end
    

    Or, you can switch to memory mapped access:

    #include "avr/io.h"
    
    .global main
    
    main:
        ldi r24, 0xFF
        sts _SFR_MEM_ADDR(DDRB), r24
        sts _SFR_MEM_ADDR(PORTB), r24
    
     end:
        jmp end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello stackoverflow community ! I am trying to figure out how to architect my
Dear StackOverflow community, I have a dataset from my university projects I am trying
stackoverflow community. I have a problem that I've been trying to solve since a
Hello again Stackoverflow community, Today I am trying to execute an application with commandline
Hi stackoverflow community I'm trying to layer images by using KineticJS. Unfortunatly it does
Hello StackOverflow community! I started to learn Node.js recently, and decided to implement a
Hello StackOverflow community, Using Google App Engine, I wrote a keyToSha256() method within a
Dear members of the Stackoverflow community, We are developing a web application using the
Hi everybody of the stackoverflow community! I've been visiting this site for years and
I want to say hello to the stackoverflow community. I've just started using knockout

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.