Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that searches for a value in memory. The value is supplied by an

ID: 664151 • Letter: W

Question

Write a program that searches for a value in memory. The value is supplied by an 8-bit number that should be read by Port C. The program should begin at memory location 0000 and increment through the entire memory range of the A3BU, with the exception of Port C itself. as this naturally contains the number for which you will search in the program. During your search, two conditions may occur 1. The value is found in memory. In this case. in a subroutine, write 0xFF to port R, which will activate a set of LEDs that are hypothetically connected to this port. Proceed to 2. OR 2. The value is not found. or you have completed step 1. In this case. read a new value from Port E. Begin the memory search. This program must be written in Atmel XMega assembly.

Explanation / Answer

CONCEPT:

Assembly code to search a value in memory..

This code will help you...

Comments are added for your understanding...

CODE:


.org 0x0
ldi r29,0x00
ldi r30,0x10
ldi r31,0xFF

start:
   // sets prtE data direction to read
   sts prtE_DIR, r29

   // loads the contents of prtE to r16
   lds r16, prtE_IN

   clr xel
   clr xeh

search:
   // load to r17 from X pointer register
   ld r17,X+

   // check to make sure it isn't comparing r17 with r16
   cpi r17, 0x10 // 0x10 is the location of r16

   breq search

   // compare r16 and r17
   cp r16,r17

   // if equal, light led
   breq lightLED

   // if at end of memory, restart
   rjmp start

   // go back to search
   rjmp search

lightled:
   // sets prtf data direction to write
   sts prtf_DIR, r30

   // loads the contents of prtE to r16
   sts prtf_OUT, r31
   // infinite loop
   rjmp lightLED

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote