Note that there are some explanatory texts on larger screens.

plurals
  1. POArduino Assembler programming: Nothing happens
    primarykey
    data
    text
    <p>Hi StackOverflow community,</p> <p>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:</p> <pre><code>// file led.c #include &lt;avr/io.h&gt; int main(void) { DDRB = 0xFF; PORTB = 0xFF; while (1) { asm("nop\n"); } return 0; } </code></pre> <p>The asm dump of the compiler results in (shortened),</p> <pre><code>ldi r24,lo8(-1) ; tmp44, out 0x4,r24 ; MEM[(volatile uint8_t *)36B], tmp44 out 0x5,r24 ; MEM[(volatile uint8_t *)37B], tmp44 </code></pre> <p>which works and activates the LED at Arduino Pin 13 (AVR pin PB5).</p> <p>But when I use this asm file,</p> <pre><code>// file led.S #include "avr/io.h" .global main main: ldi r24, 0xFF out DDRB, r24 out PORTB, r24 end: jmp end </code></pre> <p>the compiler dump results in (shortened),</p> <pre><code>ldi r24, 0xFF out ((0x04) + 0x20), r24 out ((0x05) + 0x20), r24 </code></pre> <p>what might explain why nothing happens.</p> <p>In addition here are the makefiles for the <a href="http://pastebin.com/5hdzbwxX" rel="nofollow">C version</a> and the <a href="http://pastebin.com/4yur5FAc" rel="nofollow">Assembler version</a></p> <p>Thanks for helping!</p> <p>EDIT: Here are also the full assembler dump files of the <a href="http://pastebin.com/fns0MPnb" rel="nofollow">C version</a> and the <a href="http://pastebin.com/jPG1Vc5K" rel="nofollow">Assembler version</a></p> <p>EDIT 2: I looked up the register addresses in the include file iom168.h, which references to iomx8.h, where it says <code>#define PORTB _SFR_IO8 (0x05)</code>. The compiler follows the include chain</p> <pre><code>io.h -&gt; iom168.h -&gt; iomx8.h io.h -&gt; common.h -&gt; sfr_defs.h </code></pre> <p>In sfr_defs.h is written:</p> <pre><code>#define _SFR_IO8(io_addr) ((io_addr) + __SFR_OFFSET) </code></pre> <p>A few more lines upwards the offset is defined:</p> <pre><code>#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__ &gt;= 100 # define __SFR_OFFSET 0x00 # else # define __SFR_OFFSET 0x20 # endif #endif </code></pre> <p>(Sorry for the formatting) Any idea where this error comes from?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload