Assembly Programming of Arduino/AVR Microcontrollers (AVRA Assembler)

Use avra assembler from source forge to generate hex file. The avra.exe windows executeable is available for download in reference “”.

Following is the assembly code for led blink at portb pin 5, digital pin 13 on arduino.

          .device ATmega32
          .equ PORTB = 0x05     ;Port B
          .equ DDRB = 0x04      ;Data Direction Register Port B


             ldi r16,0x20         ;set port PB5 to output mode (pin5 is set for output, numbering starting at pin0)
             out DDRB,r16

             clr r17
             eor r17,r16          ;invert output bit, eor=XOR operation
             out PORTB,r17        ;write to port
             call wait            ;wait some time
             rjmp mainloop        ;loop forever

             ldi r20,0x10         ;loop 0x400000 times
             ldi r21,0x00         ;~12 million cycles
             ldi r22,0x00         ;~0.7s at 16Mhz
             dec r22
             brne w0
             dec r21
             brne w0
             dec r20
             brne w0
  • Use the following command to upload the hex code using “avrdude.exe”. The avrdude command is installed as part of fthe arduino ide package. In fact the following command has been copied from the arduino ide. The commands being executed in arduino ide can be made visible by selecting file>preferences>”show verbose output during uploading”.

“C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude.exe” -C”C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf” -v -patmega328p -carduino -PCOM3 -b115200 -D -Uflash:w:blink.hex:I





Comments Invited

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s