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

The task is to write an assembly program to search the data stored in the memory

ID: 2085885 • Letter: T

Question


The task is to write an assembly program to search the data stored in the memory locations starting from 0x20001000 to 0x2000101C (total 8 data) for the smallest number and store it to the memory location 0x20002000. Assume that the data are stored in the memory at the beginning. Do not assign any specific values to them. The program should be general enough to work with any data in the memory in any order. Note that a memory address increments by 4, not by 1 Use the for-loop style iteration to scan all memory data in the range. Use R_0 to store the smallest number. Use R1 to count the number of iteration. Deliverables Create a s file in uVision and build the target. Debug your program until you get 0 error. Write the class and section number, your name and Homework number at the very top in comments. Then submit your .s file to BBlearner. You can change your submission up to 5 times. Due time is the midnight of February 28 (Sun).

Explanation / Answer

The task is to write an assembly program to search the data stored in the memory locations starting from 0x20001000 to 0x2000101C (total 8 data) for the smallest number and store it to the memory location 0x20002000. An equivalent C program would look like

//This C program.

int32_t            i, temp=0, data[8];       //temp is equivalent to R0 register.

for (i=7; i>=0; i--)       {if (temp>data[i]) temp=data[i];}       //compare and keep the smaller one.

Use the post-offset indirect addressing to fetch data in the memory.

baseaddr                      equ      0x20001000

index_increment          equ      4

            . .

            ldr       r2, =baseaddr

            ldr       r4, [r2], #index_increment      ;fetch the data and increment r2 address

            cmp     r0, r4               ;compare r0 and r4

            blt        move_on          ;if r0 is less than r4, move on. If not, replace

            mov     r0, r4

move_on

            sub       r1, r1, #1                     ;decrement the counter by one.

            . .
           End

for an example let us add 10 numbers and load

        LDA XXXX // Some memory location say 8500
        // Load the accumulator with the address of memory viz 8500  
        MOV D, A
        // Move the accumulator value to the register D
        MVI E, 09
        // Load the E register with the counter 10 - 1
        LXI B, XXXX + 1 // Next memory location from where we have done LDA - 8501
        // Load immediate B C with the memory location
        LDAX B
        // Load Accumulator indirect A=[BC]
        ADD D
        //Add the content of the Accumulator to the Register D
        MOV D, A
        //Move the value in D to the Accumulator or register A
        INX B
        // Increment BC register pairs
        DCR E
        // Decrement the counter register
        JNZ XXXX // LDAX B Location
        // Jump on no zero
        STA XXXX // Suitable memory location
        // Store the output into a memory location
        HLT
        // Stop the program

   

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