0% found this document useful (0 votes)
513 views2 pages

Program To Shifting The Elements in An Array in Assembly Language Using Visual Studio PDF

The document describes a program to shift the elements of a 32-bit integer array forward by one position in assembly language using Visual Studio. The code uses a loop and indexed addressing to move each element to the next position, wrapping the last element to the first position. For example, the array [10,20,30,40] would be transformed to [40,10,20,30]. The program gets the starting address of the array, initializes a new array, uses a loop to move each element, and finally moves the last element to the first position of the new array.

Uploaded by

Dilawar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
513 views2 pages

Program To Shifting The Elements in An Array in Assembly Language Using Visual Studio PDF

The document describes a program to shift the elements of a 32-bit integer array forward by one position in assembly language using Visual Studio. The code uses a loop and indexed addressing to move each element to the next position, wrapping the last element to the first position. For example, the array [10,20,30,40] would be transformed to [40,10,20,30]. The program gets the starting address of the array, initializes a new array, uses a loop to move each element, and finally moves the last element to the first position of the new array.

Uploaded by

Dilawar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 2

12/9/2018 8.

Program to Shifting the Elements in an Array in Assembly Language using Visual Studio

Programming Tutorials
SUBSCRIBE

8. Program to Shifting the Elements in an


Array in Assembly Language using Visual
Studio
February 10, 2018

Chapter 3

Assembly Language Fundamentals

Assembly Language Programming Exercise

Problem # 8:

Using a loop and indexed addressing, write code that rotates the
members of a 32-bit integer array forward one position. The value at
the end of the array must wrap around to the first position. For
example, the array [10,20,30,40] would be transformed into
[40,10,20,30].

Solution:

.386

.model flat,stdcall
.stack 4096

ExitProcess PROTO, dwExitCode:DWORD

.data
array DWORD 10,20,30,40

arrayType DWORD TYPE array

newArray DWORD LENGTHOF array DUP(?)

lastElement DWORD ?

.code

main PROC
http://csprogrammingtutorial.blogspot.com/2018/02/program-shifting-elements-in-array-in-assembly.html 1/4
12/9/2018 8. Program to Shifting the Elements in an Array in Assembly Language using Visual Studio

Programming Tutorials
;Get first element address in ESI
SUBSCRIBE
MOV ESI, OFFSET array

;Get address of next element in EDI


MOV EDI, OFFSET newArray

ADD EDI, TYPE newArray

;set loop count into ecx

mov ECX, LENGTHOF array

L2:
MOV EAX, [ESI]

MOV [EDI], EAX

ADD ESI, TYPE array

ADD EDI, TYPE array

LOOP L2

;set last element from array in newArray first position

MOV EDI,OFFSET newArray

MOV EAX, [ESI]

MOV [EDI], EAX

INVOKE ExitProcess,0

main ENDP

END main

Let me know in the comment sec on if you have any ques on.

Previous Post:

Program to Copy a String in Reverse Order in Assembly Language using Visual Studio

Next Post:

Program to Draw Text Colors in Assembly Language using Visual Studio

ASSEMBLY BASICS ASSEMBLY LANGUAGE FOR X86 PROCESSORS CHAPTER 4

COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE COMPUTER SCIENCE

DATA TRANSFERS ADDRESSING AND ARITHMETIC EXERCISE SOLUTION VISUAL STUDIO

http://csprogrammingtutorial.blogspot.com/2018/02/program-shifting-elements-in-array-in-assembly.html 2/4

You might also like