The following program should shift the position of an array's elements one position forward, with the fourth element wrapping around to the first position. This program's code incorrectly outputs the following:  1536 0 9 12 The output should read: 12 3 6 9 What can I do to fix the program so that it outputs the correct sequence of numbers? CODE: 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:   mov edx, array1[ecx - 1]   mov array1[ecx], edx   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

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter4: More Object Concepts
Section: Chapter Questions
Problem 19RQ
icon
Related questions
Question

The following program should shift the position of an array's elements one position forward, with the fourth element wrapping around to the first position. This program's code incorrectly outputs the following: 
1536

0
9
12


The output should read:
12
3
6
9

What can I do to fix the program so that it outputs the correct sequence of numbers?

CODE:

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:
  mov edx, array1[ecx - 1]
  mov array1[ecx], edx
  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

1536
Ⓒ
9
12
Microsoft Visual St
C:\Users\garci\sour
To automatically cl
le when debugging s
Press any key to cl
Transcribed Image Text:1536 Ⓒ 9 12 Microsoft Visual St C:\Users\garci\sour To automatically cl le when debugging s Press any key to cl
Expert Solution
steps

Step by step

Solved in 4 steps

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT