Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program lab5_2;
- {$APPTYPE CONSOLE}
- {$R *.res}
- uses
- System.SysUtils;
- type
- TStaticArr = array [1..100000] of longint;
- var
- n, i: longint;
- a, res1, res2: TStaticArr;
- procedure CopyStaticArray(const source: TStaticArr; var dest: TStaticArr);
- var
- i : longint;
- begin
- for i := 1 to n do
- dest[i] := source[i];
- end;
- procedure PrintStaticArray(const arr: TStaticArr);
- begin
- for i := 1 to n do
- write(arr[i], ' ');
- writeln;
- end;
- procedure BubbleSortDelphi(var arr: TStaticArr);
- var
- i, j, t: longint;
- begin
- for i := 1 to n do
- begin
- for j := 1 to n - i do
- begin
- if arr[j] > arr[j + 1] then
- begin
- t := arr[j];
- arr[j] := arr[j + 1];
- arr[j + 1] := t;
- end;
- end;
- end;
- end;
- procedure BubbleSortAsm(var arr: TStaticArr);
- var
- i, j, t: longint;
- begin
- asm
- mov edx,n
- mov i,0
- @@c1:
- mov ecx,n
- dec ecx
- xor eax,eax
- xor ebx,ebx
- mov ESI,arr
- @@c2:
- mov eax, [esi]
- add esi,4
- mov ebx, [esi]
- cmp eax,ebx
- jle @@skip
- mov [esi],eax
- sub esi,4
- mov [esi],ebx
- add esi,4
- @@skip:
- dec ecx
- cmp ecx,0
- jne @@c2
- dec edx
- cmp edx,0
- jne @@c1
- end;
- end;
- begin
- writeln('Input N: ');
- readln(n);
- writeln('Input array: ');
- for i := 1 to n do
- begin
- read(a[i]);
- end;
- CopyStaticArray(a, res1);
- CopyStaticArray(a, res2);
- BubbleSortDelphi(res1);
- BubbleSortAsm(res2);
- Write('Delphi: ');
- PrintStaticArray(res1);
- Write('Asm: ');
- PrintStaticArray(res2);
- readln;
- readln;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement