175k views
3 votes
Write an AVR assembly language program to add 0×F7A9 to 0×CB84 and save the result in R20 (low byte) and R21 (high byte).

Put this code in ATMEL Studio 7, using the ATMega328P processor in simulator mode and run the assembler. Run the code, then pause and open windows for the I/O Ports, Registers, and the assembly level code. With the program execution paused, take a full screen shot including windows showing the I/O Ports (B,C, and D), Registers, the assembly language source. Load this graphic as proof of your work.

User Clayperez
by
8.4k points

1 Answer

6 votes

Final answer:

To add 0xF7A9 to 0xCB84 in AVR assembly language, use the ADD and ADC instructions.

Step-by-step explanation:

In order to add 0xF7A9 to 0xCB84 in AVR assembly language, you can use the ADD and ADC instructions. Here is the assembly code to accomplish this:

LDI R16, 0xA9 ; Load the low byte of 0xF7A9 into R16
LDI R17, 0xF7 ; Load the high byte of 0xF7A9 into R17
LDI R18, 0x84 ; Load the low byte of 0xCB84 into R18
LDI R19, 0xCB ; Load the high byte of 0xCB84 into R19

ADD R16, R18 ; Add the low bytes
ADC R17, R19 ; Add the high bytes with carry

MOV R20, R16 ; Copy the low byte result to R20
MOV R21, R17 ; Copy the high byte result to R21

This code first loads the individual bytes of the numbers into register pairs R16:R17 and R18:R19. Then, the ADD instruction adds the low bytes and the ADC instruction adds the high bytes with carry. Finally, the MOV instruction copies the results to R20 and R21 respectively.

User Dma
by
7.2k points