SHARE
TWEET

Lab5_2 Shults

cacodemon665 Jun 2nd, 2020 903 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. program lab5_2;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. {$R *.res}
  6.  
  7. uses
  8.   System.SysUtils;
  9.  
  10. type
  11.   TStaticArr = array [1..100000] of longint;
  12.  
  13. var
  14.   n, i: longint;
  15.   a, res1, res2: TStaticArr;
  16.  
  17. procedure CopyStaticArray(const source: TStaticArr; var dest: TStaticArr);
  18. var
  19.   i : longint;
  20. begin
  21.   for i := 1 to n do
  22.     dest[i] := source[i];
  23. end;
  24.  
  25.  
  26. procedure PrintStaticArray(const arr: TStaticArr);
  27. begin
  28.   for i := 1 to n do
  29.     write(arr[i], ' ');
  30.  
  31.   writeln;
  32. end;
  33.  
  34. procedure BubbleSortDelphi(var arr: TStaticArr);
  35. var
  36.   i, j, t: longint;
  37. begin
  38.   for i := 1 to n do
  39.   begin
  40.     for j := 1 to n - i do
  41.     begin
  42.        if arr[j] > arr[j + 1] then
  43.        begin
  44.          t := arr[j];
  45.          arr[j] := arr[j + 1];
  46.          arr[j + 1] := t;
  47.        end;
  48.     end;
  49.   end;
  50. end;
  51.  
  52. procedure BubbleSortAsm(var arr: TStaticArr);
  53. var
  54.  
  55.   i, j, t: longint;
  56. begin
  57.  
  58.   asm
  59.      mov edx,n
  60.      mov i,0
  61.     @@c1:
  62.      
  63.        mov ecx,n
  64.        dec ecx
  65.        xor eax,eax
  66.        xor ebx,ebx
  67.      
  68.       mov ESI,arr
  69.     @@c2:
  70.      
  71.      
  72.      
  73.        mov eax, [esi]
  74.        add esi,4
  75.        mov ebx, [esi]
  76.      
  77.        cmp eax,ebx
  78.        jle @@skip
  79.        mov [esi],eax
  80.        sub esi,4
  81.        mov [esi],ebx
  82.        add esi,4
  83.        
  84.     @@skip:
  85.        
  86.         dec ecx
  87.         cmp ecx,0
  88.         jne @@c2
  89.        
  90.       dec edx
  91.       cmp edx,0
  92.      jne @@c1
  93.   end;
  94. end;
  95.  
  96. begin
  97.   writeln('Input N: ');
  98.   readln(n);
  99.  
  100.   writeln('Input array: ');
  101.   for i := 1 to n do
  102.   begin
  103.     read(a[i]);
  104.   end;
  105.  
  106.   CopyStaticArray(a, res1);
  107.   CopyStaticArray(a, res2);
  108.  
  109.   BubbleSortDelphi(res1);
  110.   BubbleSortAsm(res2);
  111.  
  112.   Write('Delphi: ');
  113.   PrintStaticArray(res1);
  114.   Write('Asm: ');
  115.   PrintStaticArray(res2);
  116.  
  117.   readln;
  118.   readln;
  119. end.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top