c - Compiling an Assembly Program using avr-gcc -


i trying compile simple assembly program avr-gcc run on attiny85. unfortunately, program doesn't work. , no errors while uploading , compiling. know program should work because works using c. missing?

compiling , uploading:

avr-gcc blinky.s -mmcu=attiny85 -os -g -o blinky.out avr-objcopy -o ihex blinky.out blinky.hex sudo avrdude -p attiny85 -c usbasp -p usb -e -u flash:w:blinky.hex 

blinky.s

#define f_cpu 1000000l #include <avr/io.h>          .section text         .org 0         .global init          rjmp init  init:         ldi r23,0x00         ldi r24,0xff         out _sfr_io_addr(ddrb), r24         out _sfr_io_addr(portb), r23          rjmp main          .org 0x020         .global main main:         out _sfr_io_addr(portb), r24         rjmp main 

output:

philipps-macbook-pro:desktop philippbraun$ sh script.sh attiny85 blinky.s  avrdude: avr device initialized , ready accept instructions  reading | ################################################## | 100% 0.00s  avrdude: device signature = 0x1e930b avrdude: erasing chip  avrdude: safemode: fuses ok  avrdude done.  thank you.  compiling assembly file  avrdude: avr device initialized , ready accept instructions  reading | ################################################## | 100% 0.00s  avrdude: device signature = 0x1e930b avrdude: erasing chip avrdude: reading input file "blinky.hex" avrdude: input file blinky.hex auto detected intel hex avrdude: writing flash (46 bytes):  writing | ################################################## | 100% 0.03s    avrdude: 46 bytes of flash written avrdude: verifying flash memory against blinky.hex: avrdude: load data flash data input file blinky.hex: avrdude: input file blinky.hex auto detected intel hex avrdude: input file blinky.hex contains 46 bytes avrdude: reading on-chip flash data:  reading | ################################################## | 100% 0.03s    avrdude: verifying ... avrdude: 46 bytes of flash verified  avrdude: safemode: fuses ok  avrdude done.  thank you. 

the following c program compiles successfully!

#define f_cpu 1000000l #include <avr/io.h> #include <util/delay.h>  int main(void) { ddrb = 0xff; // portb output, pins portb = 0x00; // make pins low start  (;;) { portb = 0xff; // invert pins //_delay_ms(5000); // wait time } return 0; } 

first wondering can assembly command line! me doesn't work!

so want achieve? compile stdlib support ( irq jump table, jump main @ start? or want hand?

do hand:

avr-gcc -xassembler-with-cpp x.s -mmcu=attiny85 -nostdlib 

use stdlib jump table:

avr-gcc -xassembler-with-cpp x.s -mmcu=attiny85 

if use without jump table should use avr-as instead of avr-gcc!

so tried code hand crafted version , assembly empty! why?

you have typo:

.section text 

is wrong!

use:

.section .text 

my dump looks that:

00000000 <init>:    0:   8f ef           ldi r24, 0xff   ; 255    2:   87 bb           out 0x17, r24   ; 23    4:   0d c0           rjmp    .+26        ; 0x20 <main> ...  00000020 <main>:   20:   88 bb           out 0x18, r24   ; 24   22:   fe cf           rjmp    .-4         ; 0x20 <main> 

nothing blinks here!

next: why use .org here? if add init larger 0x020 in code size overridden main! remove dirty lines!

#include <avr/io.h>      ldi r23,0x00     ldi r24,0xff     out _sfr_io_addr(ddrb), r24  main:     out _sfr_io_addr(portb), r24     out _sfr_io_addr(portb), r23     rjmp main 

results in:

00000000 <__ctors_end>:    0:   70 e0           ldi r23, 0x00   ; 0    2:   8f ef           ldi r24, 0xff   ; 255    4:   87 bb           out 0x17, r24   ; 23  00000006 <main>:    6:   88 bb           out 0x18, r24   ; 24    8:   78 bb           out 0x18, r23   ; 24    a:   fd cf           rjmp    .-6         ; 0x6 <main> 

and why have used .global ? nobody references externally on defined symbols init , main.

so if use version stdlib, have export main make visible start code. if want that, there no way use init before main. know avr-libc has no idea user init method @ all.


Comments