Answer :
Answer:
Here is the code which will rotate the array.
*************************************************************************
.386
.model flat,stdcall
.stack 4096
ExitProcess PROTO, dwExitCode:DWORD
section .data
array DWORD 10,20,30,40 ; Initialising the array
arrayType DWORD TYPE array
newArray DWORD LENGTHOF array DUP(?)
lastElement DWORD ?
.code
main PROC
;First Element will be moved to register ESI
mov ESI, OFFSET array
;Next Array Element in EDI
mov EDI, OFFSET newArray
ADD EDI, TYPE newArray
;Loop Counter set into register ECX
mov ECX, LENGTHOF array
L2:
mov EAX, [ESI]
mov [EDI], EAX
ADD ESI, TYPE array
ADD EDI, TYPE array
LOOP L2
; following will set the last element of array into first position of newArray
mov EDI,OFFSET newArray
mov EAX, [ESI]
mov [EDI], EAX
INVOKE ExitProcess,0
main ENDP
END main
Explanation:
.386 - It will enable assembly of non privileged instruction for 80386 processor.
.model flat, stdcall - It will explain about which memory to use.
.stack 4096 - It is used to inform assembler to reserver 4096 bytes of uninitialised memory.
.code is a code section.
section .data is used to declare initialized data.
DWORD is a type specified with 4 bytes address.
EAX, EDI, ESI, ECX are Registers
mov- It will move data from one register to another.
ADD- Add two values.