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

Write a 32-bit MASM Assembly program with a LOOP AND INDEXED ADDRESSING that cal

ID: 3762182 • Letter: W

Question

Write a 32-bit MASM Assembly program with a LOOP AND INDEXED ADDRESSING that calculates the sum of all gaps between successive array elements. The array that MUST be used is:


myArray DWORD 0,2,5,9,10

So, the gaps between the numbers in the array would be 2, 3, 4, and 1, which equals 10. How can I use the following to solve this?


myArray[esi] and myArray[esi+4]

esi must be used as an array index, you must create a loop that implenets this, and increment esi as you loop through the program. Please comment your code if you respond to this question so others may understand the process.

Explanation / Answer

add eax,[ebx+ecx*4] and sub eax,[ebx+ecx*4-4]

==================================

Register usage:
!   %r1-consists of array length
!      %r2-starting address of array
!      %r3-contains indicator
!      %r4-array pointer
!       %r7-holds a near top element
!      %r8-holds a near bottom element

        .begin
        .org 2048
   a_start .equ   4000  
   main:        addcc %r0, 1, %r3
        ld[length], %r5
        ld[address], %r2
   outloop: andcc %r5, %r5, %r0
        be done
loop: add eax,[ebx+ecx*4] and sub eax,[ebx+ecx*4-4]
        addcc   %r3, %r7, %r4
        ld    %r4, %r8
        ld[address+4], %r9
        subcc %r2, %r9, %r10 !substracts two values, store in 10
        bneg swap !if negative, do swap
        addcc %r2, 4, %r2 !moves address up 4 bits
        ba loop
done:       halt
swap:       st %r9,[address]
        st %r2,[address+4]
        ba loop   
address:    a_start
        .org     a_start
a: 0
2
5
9
10
    .end

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