Deutsch English Espanol Francais Italiano Nihongo Nederlands Portuguese

C++
Bubble Sort Algorithm

Perform a bubblesort in assembly language. At the start of the program, using C/C++ output functions, output a program identifier that includes your name to the screen. Using an assembly language LOOP and C/C++ I/O, create appropriate user prompts and input 10 numbers from the keyboard into an array variable numbers_abc (where abc = your initials). Using the same algorithm you used in the first program, build the bubblesort routine in assembly language and sort the numbers in ascending order. Put the sorted numbers into an array sorted_abc (where abc = your initials). Using an assembly language LOOP and C/C++ I/O, display the both the original unsorted numbers and sorted numbers. Identify each set of numbers and put each set on a single line separated by commas, as shown below.


#include <iostream.h>

source code:

int main()
{

int numbers [10];
int i;

cout<<"Please enter 10 numbers to be sorted:\n\n";
for (i = 0; i < 10 ; i++ )

cin>>numbers [i];

cout<<"\nUnsorted:\n";
for (i = 0; i <= 10-1; i++)
cout<< numbers [i]<<" ";
cout<<"\n\nSorted:\n";

_asm
{
mov edx,9

outerloop:
lea edi,numbers;
mov ecx,9;

Loop1: mov eax,[edi];
mov ebx,[edi+4];
cmp ebx,eax;
jae Loop2;
mov [edi + 4],eax;
mov [edi],ebx;

Loop2: add edi,4;
Loop Loop1;
sub edx, 1;
cmp edx, 0;
jnz outerloop;

}
for (i = 0; i <= 10-1; i++)
cout<<numbers[i]<<" ";
cout<<endl<<"\n";
return 0;

}

output window:

Please enter 10 numbers to be sorted:

11
33
55
99
88
66
44
77
22
101

Unsorted:
11 33 55 99 88 66 44 77 22 101

Sorted:
11 22 33 44 55 66 77 88 99 101

Press any key to continue

As you can see the program ran as it was supposed to.

References

Juicy Studio, Great Code Examples
C and C++ Referance Materials

Related

DSP Derivative Filter Matlab Tutorial Hann Window

Topics

Tech Business Computer Engineering Electrical Engineering Selected Topics

© Copyright 2005 Castelarhost.com