SHIFTING THE ELEMENTS IN AN ARRAY Using a loop and indexed addressing, write code that rotates the members of a 32-bit integer array forward one position; rotating elements in the SAME array, NOT copying elements to a new array with shifted positions. The value at the end of the array must wrap around to the first position. For example, the array [10h, 20h, 30h, 40h] would be transformed into [40h, 10h ,20h,30h]. In the output of the program, the array values both before and after shifting should be shown, by calling the Irvine peripheral procedure(s). IMPORTANT: for this exercise, NOT allowable to use any one of these directives: .IF, .ELSE, .ELSEIF, WHILE, .REPEAT, etc
can you show me the screen shot of the out put
INCLUDE Irvine32.inc
.DATA
array DWORD 10h, 20h, 30h, 40h
arraySize = ($ - array) / TYPE array
.CODE
main PROC
; Display the array values before shifting
CALL DumpMem
CALL Crlf
; Rotate the elements of the array forward one position
MOV EAX, array[arraySize - 1] ; Save the last element of the array in EAX
MOV ECX, arraySize - 1
rotateLoop:
MOV EDX, array[ECX - 1] ; Move the previous element into EDX
MOV array[ECX], EDX ; Move the previous element into the current element
LOOP rotateLoop
MOV array[0], EAX ; Move the last element into the first element
; Display the array values after shifting
CALL DumpMem
CALL Crlf
CALL WaitMsg
RET
main ENDP
END main
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 3 images