12/9/2018 6.
Program to Reverse an Array in Assembly Language using Visual Studio
Programming Tutorials
SUBSCRIBE
6. Program to Reverse an Array in Assembly
Language using Visual Studio
December 13, 2017
Chapter 3
Assembly Language Fundamentals
Assembly Language Programming Exercise
Problem # 6:
Use a loop with indirect or indexed addressing to reverse the elements
of an integer array in place. Do not copy the elements to any other
array. Use the SIZEOF, TYPE, and LENGTHOF operators to make the
program as flexible as possible if the array size and type should be
changed in the future.
Solution:
.386
.model flat,stdcall
.stack 4096
ExitProcess PROTO, dwExitCode:DWORD
.data
decimalArray DWORD 1,2,3,4,5,6,7,8
.code
main PROC
MOV ESI, OFFSET decimalArray
MOV EDI, OFFSET decimalArray
mov ecx, LENGTHOF decimalArray-1
L1:
http://csprogrammingtutorial.blogspot.com/2017/12/Reverse-an-Array-using-loop.html 1/5
12/9/2018 6. Program to Reverse an Array in Assembly Language using Visual Studio
ADD EDI, TYPE decimalArray
Programming Tutorials
LOOP L1
SUBSCRIBE
mov ecx, LENGTHOF decimalArray
L2:
MOV EAX, [ESI]
MOV EBX, [EDI]
XCHG EAX, EBX
MOV [ESI], EAX
MOV [EDI], EBX
ADD ESI, TYPE decimalArray
SUB EDI, TYPE decimalArray
DEC ECX
LOOP L2
INVOKE ExitProcess,0
main ENDP
END main
OR
.386
.model flat,stdcall
.stack 4096
ExitProcess PROTO, dwExitCode:DWORD
.data
decimalArray DWORD 1,2,3,4,5,6,7,8
.code
main PROC
MOV ESI, OFFSET decimalArray
MOV EDI, OFFSET decimalArray
ADD EDI, SIZEOF decimalArray
SUB EDI, TYPE decimalArray
http://csprogrammingtutorial.blogspot.com/2017/12/Reverse-an-Array-using-loop.html 2/5
12/9/2018 6. Program to Reverse an Array in Assembly Language using Visual Studio
mov ecx, LENGTHOF decimalArray
Programming Tutorials
L2:
SUBSCRIBE
MOV EAX, [ESI]
MOV EBX, [EDI]
XCHG EAX, EBX
MOV [ESI], EAX
MOV [EDI], EBX
ADD ESI, TYPE decimalArray
SUB EDI, TYPE decimalArray
DEC ECX
LOOP L2
INVOKE ExitProcess,0
main ENDP
END main
Let me know in the comment sec on if you have any ques on.
Previous Post:
Fibonacci Numbers
Next Post:
Program to Copy a String in Reverse Order 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
Reactions: funny (0) interesting (0) cool (0)
http://csprogrammingtutorial.blogspot.com/2017/12/Reverse-an-Array-using-loop.html 3/5
12/9/2018 6. Program to Reverse an Array in Assembly Language using Visual Studio
Programming Tutorials
SUBSCRIBE
Popular Posts
8. Program to Shifting the Elements in an Array in Assembly Language
using Visual Studio
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 …
1. Program for converting from Big Endian to Little Endian in Assembly
Language using Visual Studio
Chapter 4 Data Transfers, Addressing, and Arithmetic Assembly Language
Programming Exercise Problem # 1: Write a program that uses the variables below
and MOV instructions to copy the value from bigEndian to littleEndian, reversing the
order of the bytes. The number’s 32-bit value is understood to be 12345678 …
3. Program for Summing the Gaps between Array Values in Assembly
Language using Visual Studio
Chapter 4 Data Transfers, Addressing, and Arithmetic Assembly Language
Programming Exercise Problem # 3: Write a program with a loop and indexed
addressing that calculates the sum of all the gaps between successive array
elements. The array elements are doublewords, sequenced in non decreasing order.…
http://csprogrammingtutorial.blogspot.com/2017/12/Reverse-an-Array-using-loop.html 4/5
12/9/2018 6. Program to Reverse an Array in Assembly Language using Visual Studio
Programming Tutorials
SUBSCRIBE
Powered by Blogger
http://csprogrammingtutorial.blogspot.com/2017/12/Reverse-an-Array-using-loop.html 5/5