Question

Free response You're working with a team of firmware engineers on a big project using the...

Free response

You're working with a team of firmware engineers on a big project using the AVR architecture. Part of your work requires you to write a short assembly subroutine to swap the values stored at RAM memory locations 0xFA00 and 0xFA01. Write this routine below and give it the subroutine name "swap", using best practices in firmware design. Place the swap subroutine at the ROM (flash) location 0x0A00.

Homework Answers

Answer #1

Answer :- The AVR assembly subroutine has been written below-

.CSEG ;in code code segment
.ORG 0x0A00 ;start from address 0x0A00 in code memory

;get the first memory address value, keep it in R16
LDI R26, 0x00 ;R26 = 0x00
LDI R27, 0xFA ;R27 = 0xFA
LD R16, X ;R16 = value at address 0xFA00

;get the second memory address value, keep it in R17
LD R17, +X ;R17 = value at address 0xFA01

;store back the register values to swap
ST X, R16 ;copy value in R16 to address 0xFA01
ST R -X, 17 ;copy value in R17 to address 0xFA00

RET ;return from the subroutine

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT