0% found this document useful (0 votes)
4 views

Assembly-programming-through-Arduino-Additionalmaterial

The document provides a reference for using assembly language with Arduino, detailing key assembly keywords and their functions. It includes information on the ATmega328 pin mapping to Arduino, as well as the DDRX, PORTX, and TCCR0B registers that control pin functions and settings. Additionally, it outlines a step-by-step procedure for installing AVRdude on Windows, including necessary commands to verify installation success.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Assembly-programming-through-Arduino-Additionalmaterial

The document provides a reference for using assembly language with Arduino, detailing key assembly keywords and their functions. It includes information on the ATmega328 pin mapping to Arduino, as well as the DDRX, PORTX, and TCCR0B registers that control pin functions and settings. Additionally, it outlines a step-by-step procedure for installing AVRdude on Windows, including necessary commands to verify installation success.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Arduino - Assembly code reference

Keywords used in Arduino for Assembly language programming:


Keyword Example Function
ldi ldi r16, Loads the binary value into the register
0b00001000
out out PORTB, r16 Sends the value of r16 to PORTB
in in r16, PORTB Reads the value of PORTB and stores it in r16
rjmp rjmp Jumps to the AddressLabel
AddressLabel
rcall rcall Calls the AddressLabel
AddressLabel
mov mov r16, r17 Moves the value from r17 to r16
clr clr r16 or clr Clears the value stored in the register
PORTB
and and r16, r17 Performs bitwise AND operation and stores result in
r16
or or r16, r17 Performs bitwise OR operation and stores result in
r16
eor eor r16, r17 Performs bitwise XOR operation and stores result in
r16
lsl lsl r16 Performs left shift in a loop on the value stored in r16
dec dec r16 Decrements the value stored in r16 by 1
brne brne Go to the AddressLabel if zero flag is not set
AddressLabel
ret ret Exits the subroutine loop
sbi sbi r16, 4 Sets the 5th bit of register 16 to 1
breq breq Goes to the AddressLabel if zero flag is set
AddressLabel
1)Atmega328 to Arduino Pin Mapping
The above diagram depicts the manner in which the pins of the ATmega328 are mapped
to the pins on the Arduino board. The red text represents the names you can see on the
Arduino board. The black text represents the pins on the ATmega328.
ATmega328 has a total of three ports namely Port B (PB), Port C (PC) and Port D
(PD). Each of these ports has eight bits corresponding to the function according to pin
out. There are lot of registers in the Atmega board which tells the board how to function
essentially. The registers used in our programs are mainly DDRX, PORTX, TCCR0B
where X being the port name such as B,C or D.
2) DDRX Register
This register has 8 bits corresponding to 8 pins of that respective port. For example
DDRB corresponds to PORT B and controls the function of Port B pins. Making a bit of
DDRB as high makes the corresponding pin of PORT B as output and vice versa.
Before using the pins as input or output in the assembly code, it is essential to always set
this register according to our exact function i.e., input or output.
3) PORTX Register
This register has 8 bits corresponding to 8 pins of that respective port. For example
PORT B corresponds to port B and controls the value of Port B pins. Making a bit of
PORT B as high makes the corresponding pin of PORT B as high and vice versa.
If PORT B is set as a output, then “out PORTB, r16” will write the value of r16 into
PORT B register making it high or low according to the value of r16.
If PORT B is set as a input, then “in r16, PORTB” will read the value from PORT B and
write the corresponding value into r16.
4) TCCR0B
This register has 8 bits and first three bits that is bit0, bit1 and bit2 together acts as a
prescaler settings. Depending on what is written in these bits, the crystal frequency is
manipulated to get clock of different frequency. The method of doing this manipulation is
called prescaling.

===============================================================
The procedure to Install AVRdude on Windows: (Intermediate Level)
=======================================================
1. To follow the installation procedure, you need to be connected to the Internet.
2. Download the latest version of WinAVR package from the given link.
https://sourceforge.net/projects/winavr/
3. Click on Download button to download the WinAVR package.
4. Click on the save button to save the file.
5. Locate the file that you have downloaded. Right click on it and select Run as
administrator.
6. User Account Control popup window will appear. Click on Yes.
7. Installer Language dialog box will appear. Select English and click on OK.
8. In the Setup Wizard, click on Next.
9. In the License Agreement window, click on I Agree.
10. In Choose Install Location dialog box, keep the default installation location and
click on Next.
11. In Choose Components dialog box, check all three check boxes and then click on
Install. This will start the installation.
12. After the installation is successfully completed, click on Finish to close the wizard.
13. Now open command prompt. To do so, in the search bar type command prompt and
click on the command prompt application.
14. Run the following commands in the command prompt to make sure all the required
utilities are available. You will see the version number.
>Avr-gcc -v
>avr-objcopy -v
>make -v
>avrdude

You might also like