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

Overview: The intent of this Lab assignment is to introduce you to more asm inst

ID: 3669955 • Letter: O

Question

Overview: The intent of this Lab assignment is to introduce you to more asm instructions/rules including working with different size data, variations of the move command, the XCHG instruction, simple LOOP and ARRAY manipulations, and indirect addressing.

1. Create a BYTE array containing the integers 2-4-6-8-10

2. Use a loop to move these integers into an array of datatype DWORD

3. Use another loop to display the contents of this DWORD array to the console.

4. Use the XCHG instruction to reorder the integers to 10-8-6-4-2 5. Display contents again.

mov eax, Array1[esi] where esi is a counter for each array element

mov eax, [ebx] - where ebx points to an array value

Use WriteChar to put spaces between the integers you display. Use WriteDec to display the integers. Use Crlf to provide line feeds.

Explanation / Answer

; data definitions
Array1 db 2, 4, 6, 8, 10
Array2 rd 5 ; reserve 5 dwords for the second array.

; the code
mov esi, Array1
mov edi, Array2
mov ecx, 5

copy_loop:
movzx eax, byte [esi] ; this instruction assumes the numbers are unsigned.
; if the byte array contains signed numbers use
; "movsx"

mov [edi], eax ; store to the dword array

inc esi
add edi, 4 ; <-- notice, the next cell is 4 bytes ahead!

loop copy_loop ; the human-friendly labels will not affect the
; speed of the program.