Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. section .data
  2.     scanffmt: db "%d %d %d", 0
  3.     printnfmt: db "%d ", 0
  4.     printlnfmt: db "", 10, 0
  5.  
  6. section .bss
  7.     inputm: resd 1
  8.     inputn: resd 1
  9.     inputt: resd 1
  10.     anscnt: resd 1
  11.     maxnum: resd 1
  12.  
  13. section .text
  14.  
  15.     global isPrime
  16.     global asmMain
  17.  
  18.     extern scanf
  19.     extern printf
  20.  
  21. isPrime:
  22.  
  23.     push rbp
  24.     mov rbp, rsp
  25.  
  26.     mov ecx, 2
  27.  
  28.     sqrt:
  29.  
  30.         mov [inputm], edi
  31.         fild dword [inputm]
  32.         fsqrt
  33.         fistp dword [inputm]
  34.         mov edi, [inputm]
  35.  
  36.     primeloop:
  37.    
  38.         cmp edi,ecx
  39.         jl endwithtrue
  40.  
  41.         mov edx, 0
  42.         mov eax, ebx
  43.         div ecx
  44.  
  45.         cmp edx, 0
  46.         je endwithfalse
  47.  
  48.         inc ecx
  49.         jmp primeloop
  50.  
  51.     endwithtrue:
  52.    
  53.         mov eax, 1
  54.         pop rbp
  55.         ret
  56.  
  57.     endwithfalse:
  58.  
  59.         mov eax, 0
  60.         pop rbp
  61.         ret
  62.  
  63. asmMain:
  64.  
  65.     push rbp
  66.     mov rbp, rsp
  67.    
  68.     mov dword [anscnt], 0
  69.  
  70.     scan:
  71.  
  72.         ;SYSTEMV AMD64 ADI
  73.         mov ecx, inputt
  74.         mov edx, inputn
  75.         mov esi, inputm
  76.         mov edi, scanffmt
  77.         xor eax, eax
  78.         call scanf 
  79.  
  80.     minmax:
  81.  
  82.         mov eax, [inputm]
  83.         mov ebx, [inputn]
  84.         cmp eax, ebx
  85.         jle set_n_as_max
  86.    
  87.     set_m_as_max:
  88.  
  89.         mov eax, [inputm]
  90.         mov [maxnum], eax
  91.         mov ebx, [inputn]
  92.         jmp loophead
  93.  
  94.     set_n_as_max:
  95.  
  96.         mov eax, [inputn]
  97.         mov [maxnum], eax
  98.         mov ebx, [inputm]
  99.  
  100.     loophead:
  101.  
  102.         mov edi, ebx
  103.         call isPrime
  104.  
  105.         cmp eax, 1
  106.         je print
  107.         jmp looptail
  108.  
  109.     print:
  110.  
  111.         inc dword [anscnt]
  112.         mov esi, ebx
  113.         mov edi, printnfmt
  114.         call printf
  115.  
  116.         mov edx, 0
  117.         mov eax, [anscnt]
  118.         div dword [inputt]
  119.        
  120.         cmp edx, 0
  121.         je println
  122.         jmp looptail
  123.  
  124.     println:
  125.  
  126.         mov edi, printlnfmt
  127.         call printf
  128.  
  129.     looptail:
  130.        
  131.         inc ebx
  132.         cmp ebx, [maxnum]
  133.         jle loophead
  134.  
  135.     endprint:
  136.  
  137.         mov edi, printlnfmt
  138.         call printf
  139.  
  140.         mov esi, [anscnt]
  141.         mov edi, printnfmt
  142.         call printf
  143.  
  144.     end:
  145.  
  146.         pop rbp
  147.         ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement