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

. Make a assembly masm irvine 32 program that uses arrays of randomly ordered in

ID: 3720926 • Letter: #

Question

. Make a assembly masm irvine 32 program that uses arrays of randomly ordered integers.

Make a modified version of a "swap" procedure

Write a loop that starts from the outside and moves inwards, exchanging every other consecutive pair of integers in the array

Use "Chapter 8" style input limitations

Make sure all registers are put back to their original status when done

You must assume that there will be a multiple of 4 number of elements in your array (4, 8, 12, ...)

Test your program as much as you can

Example

1 2 3 4 5 6 7 8

1 and 8 swap to become 8 2 3 4 5 6 7 1

2 and 7 are not swapped

3 and 6 swap to become 8 2 6 4 5 3 7 1

4 and 5 are not swapped  

8 2 6 4 5 3 7 1

Explanation / Answer

As per your requirement I have written code which fulfill all your requirements please follow it step by step

TITLE SwappingElement (SwappingElement.asm)

; Here we will write program Description :

; First of all create an array of randomly ordered integers. Using the Swap procedure from Sec 8.4.6 as a tool, Later write a loop that exchanges each consecutive pair of integers in an array.

INCLUDE Irvine32.inc

Swap PROTO, pointerArr:PTR DWORD, sizeArr:DWORD

.data

array DWORD 1,2,3,4,5,6,7,8

.code

main PROC

pushad

mov esi,OFFSET array

mov ecx, LENGTHOF array

mov ebx,TYPE array

call DumpMem

INVOKE Swap, ADDR Array, LENGTHOF array/2

call DumpMem

call Crlf

popad

exit

main ENDP

Swap PROC USES eax esi edi ecx, pointerArr:PTR DWORD, sizeArr:DWORD

mov esi,pointerArr

mov edi,pointerArr

add edi,SIZEOF DWORD

mov ecx,sizeArr

L1:

mov eax,[esi]

xchg eax,[edi]

mov [esi],eax

add esi,SIZEOF DWORD

add esi,SIZEOF DWORD

add edi,SIZEOF DWORD

add edi,SIZEOF DWORD

loop L1

ret

Swap ENDP

END main