The following program has an error. Please help resolve. INCLUDE Irvine32.inc .data array1 DWORD 3, 6, 9, 12 ; declare and initialize an array of 4 double word elements .code main PROC mov edi, LENGTHOF array1 ; find the size of array and assign to edi mov eax, array1[edi - 1] ; store the value of the last element in the array in eax ; Loop to shift array elements one position to the left (forward) and wrap the last element to the first position mov ecx, edi dec ecx ; ecx = edi - 1, as we want to exclude the last element from the loop L1: dec ecx ; Decrement ecx before moving the array elements mov edx, array1[ecx] mov array1[ecx + 1], edx ; Increment ecx when moving elements to shift them forward loop L1 mov array1[0], eax ; assign the first element the value held in eax (the original value of the last element) ; Loop to print array values mov ecx, LENGTHOF array1 mov esi, OFFSET array1 L2: mov eax, [esi] call WriteDec call Crlf add esi, TYPE array1 loop L2 exit
The following program has an error. Please help resolve.
INCLUDE Irvine32.inc
.data
array1 DWORD 3, 6, 9, 12 ; declare and initialize an array of 4 double word elements
.code
main PROC
mov edi, LENGTHOF array1 ; find the size of array and assign to edi
mov eax, array1[edi - 1] ; store the value of the last element in the array in eax
; Loop to shift array elements one position to the left (forward) and wrap the last element to the first position
mov ecx, edi
dec ecx ; ecx = edi - 1, as we want to exclude the last element from the loop
L1:
dec ecx ; Decrement ecx before moving the array elements
mov edx, array1[ecx]
mov array1[ecx + 1], edx ; Increment ecx when moving elements to shift them forward
loop L1
mov array1[0], eax ; assign the first element the value held in eax (the original value of the last element)
; Loop to print array values
mov ecx, LENGTHOF array1
mov esi, OFFSET array1
L2:
mov eax, [esi]
call WriteDec
call Crlf
add esi, TYPE array1
loop L2
exit
main ENDP
END main
Step by step
Solved in 3 steps