Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
312 views

Program For Exchanging Pairs of Array Values in Assembly Language Using Visual Studio PDF

The document describes a program written in assembly language that exchanges pairs of values in an array with an even number of elements. The program uses a loop and indexed addressing. It moves the first element into a register, exchanges it with the next element, and moves it back, then increments the index by 4 to jump to the next pair. This exchanges each pair of elements in the array. The program is a solution to an exercise problem of writing a loop to exchange pairs of values in an array.

Uploaded by

Dilawar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
312 views

Program For Exchanging Pairs of Array Values in Assembly Language Using Visual Studio PDF

The document describes a program written in assembly language that exchanges pairs of values in an array with an even number of elements. The program uses a loop and indexed addressing. It moves the first element into a register, exchanges it with the next element, and moves it back, then increments the index by 4 to jump to the next pair. This exchanges each pair of elements in the array. The program is a solution to an exercise problem of writing a loop to exchange pairs of values in an array.

Uploaded by

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

12/9/2018 2.

Program for Exchanging Pairs of Array Values in Assembly Language using Visual Studio

Programming Tutorials
SUBSCRIBE

2. Program for Exchanging Pairs of Array


Values in Assembly Language using Visual
Studio
December 13, 2017

Chapter 4

Data Transfers, Addressing, and Arithmetic

Assembly Language Programming Exercise

Problem # 2:

Write a program with a loop and indexed addressing that exchanges


every pair of values in an array with an even number of elements.
Therefore, item i will exchange with item i+1, and item i+2 will
exchange with item i+3, and so on.

Solution:

.386
.model flat,stdcall

.stack 4096
ExitProcess proto,dwExitCode:dword

.data

array dword 1,2,3,4,5,6,7,8

.code
main proc

mov esi, OFFSET array

mov ecx, LENGTHOF array -1

myLoop:

MOV eax,[esi]
http://csprogrammingtutorial.blogspot.com/2017/12/exchanging-pairs-of-array-values.html 1/3
12/9/2018 2. Program for Exchanging Pairs of Array Values in Assembly Language using Visual Studio

XCHG eax,[esi+4]
Programming Tutorials
MOV [esi],eax
SUBSCRIBE

add esi, TYPE array

add esi, TYPE array

loop myLoop

invoke ExitProcess,0

main endp

end main

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

Previous Post:

Conver ng from Big Endian to Li le Endian

Next Post:
Summing the Gaps between Array Values

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/exchanging-pairs-of-array-values.html 2/3

You might also like