Advertisement
Guest User

Untitled

a guest
Feb 15th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         .data              /* секция данных */
  2.         .text              /* секция кода программы */
  3. scanf_4_ints:
  4.         .asciz  "%d %d %d %d"
  5. printf_1_int:
  6.         .asciz  "%d\n"
  7.         .global process
  8. min_max:                   /* %eax is min, %edx is max */
  9.         pushl   %ebp
  10.         movl    %esp, %ebp
  11.  
  12.         movl    8(%ebp), %eax
  13.         movl    12(%ebp), %edx
  14.         cmpl    %edx, %eax
  15.        
  16.         jl      less
  17. greater:
  18.         xorl    %eax, %edx  /* super swap */
  19.         xorl    %edx, %eax
  20.         xorl    %eax, %edx
  21. less:
  22.         movl    %ebp, %esp
  23.         popl    %ebp
  24.         ret
  25.  
  26. process:
  27.         pushl   %ebx
  28.         movl    $0, %ebx
  29.         pushl   %ebp
  30.         movl    %esp, %ebp
  31.        
  32.         subl    $16, %esp   /* Memory for input data */
  33. loop:
  34.         leal    -16(%ebp), %eax       /* Pointers for scanf */
  35.         pushl   %eax
  36.         leal    -12(%ebp), %eax
  37.         pushl   %eax
  38.         leal    -8(%ebp), %eax
  39.         pushl   %eax
  40.         leal    -4(%ebp), %eax
  41.         pushl   %eax
  42.  
  43.         pushl   $scanf_4_ints
  44.         call    scanf
  45.  
  46.         cmpl    $4, %eax
  47.         jnz     end
  48.         addl    $16, %esp
  49.  
  50.         pushl   -4(%ebp)
  51.         pushl   -12(%ebp)
  52.         call    min_max
  53.         movl    %edx, -4(%ebp)
  54.  
  55.         pushl   -8(%ebp)
  56.         pushl   -16(%ebp)
  57.         call    min_max
  58.        
  59.         movl    -4(%ebp), %edx
  60.         subl    %edx, %eax
  61.  
  62.         jnl     everything_is_ok
  63. of:
  64.         movl    $0, %eax
  65. everything_is_ok:
  66.         addl    %eax, %ebx
  67.         jmp     loop
  68. end:    
  69.         pushl   %ebx
  70.         pushl   $printf_1_int
  71.         call    printf
  72.  
  73.         movl    %ebp, %esp
  74.         popl    %ebp
  75.         popl    %ebx
  76.         ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement