ATMEL Studio 7 Does Blink in Assembly Language

as7b

See the previous post (here) for detailed information on AS7 installation and simulating of an Arduino program execution. As an exercise to gain familiarity with AS7, lets make an assembly language project using the below Blink code:

• Select “File>New>Project”.

• Assembler.

• AVR Assembler Project.

• Give it a unique name.

• Select the proper device.

Remember to select the Simulator in order to run the program inside the AS7 IDE. See the previous post on how to do this. Here is a screen shot of the assembly code running in AS7:

as7-a

Here is the code for a very basic assembly language blink program:

.include "m168pdef.inc"

.org 0x0000
   rjmp start
start:
    ldi r16, 0           ; reset system status
    out SREG, r16        ; init stack pointer
    ldi r16, low(RAMEND)
    out SPL, r16
    ldi r16, high(RAMEND)
    out SPH, r16

    sbi DDRB, DDB5       ;pinMode(13, OUTPUT);
_loop:
    sbi PORTB, PORTB5    ;turn LED on
    rcall _delay
    cbi PORTB, PORTB5    ;turn LED off
    rcall _delay
    rjmp _loop

_delay:
    ldi r24, 0x00        ;one second delay iteration
    ldi r23, 0xd4 
    ldi r22, 0x30 
_d1:                     ;delay ~1 second
    subi r24, 1   
    sbci r23, 0   
    sbci r22, 0
    brcc _d1
    ret

Now, start learning inline assembly language:

Also available as a book, with greatly expanded coverage!

BookCover
[click on the image]

About Jim Eli

µC experimenter
This entry was posted in arduino, assembly language and tagged , , , , , , , . Bookmark the permalink.

Leave a comment