Advertisement
Dari_

find amount of numbers

Mar 10th, 2019
653
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. %include "io.inc"
  2.  
  3. section .bss
  4.     N resd 1
  5.     K resd 1
  6.     m resd 1
  7.     r resd 1
  8.     res resd 1
  9.     deg resd 1
  10.     prom resd 1
  11.     i resd 1
  12.  
  13. section .text
  14. global CMAIN
  15. CMAIN:
  16.     GET_DEC 4, [N]
  17.     GET_DEC 4, [K]
  18.     mov dword[m], 0
  19.     mov dword[deg], 1
  20.     mov dword[res], 0
  21.    
  22.    
  23.     .ret:
  24.     mov esi, dword[deg]
  25.     cmp esi, dword[N]
  26.     jg .st
  27.     mov eax, dword[deg]
  28.     mov esi, 2
  29.     mul esi
  30.     mov dword[deg], eax
  31.     inc dword[m]
  32.     jmp .ret
  33.     .st:
  34.    
  35.     mov eax, dword[deg]
  36.     mov esi, 2
  37.     div esi
  38.     mov dword[deg], eax
  39.     dec dword[m]
  40.    
  41.     PRINT_DEC 4, [m]
  42.     NEWLINE
  43.    
  44.     LOOP:
  45.     mov dword[prom], 1
  46.     mov ebp, 1
  47.    
  48.     inc dword[m]
  49.     .ret1:
  50.     cmp ebp, dword[m]
  51.     je .factor
  52.     mov eax, dword[prom]
  53.     mul ebp
  54.     mov dword[prom], eax
  55.     inc ebp
  56.     jmp .ret1
  57.     .factor:
  58.     PRINT_DEC 4, [prom]
  59.     NEWLINE
  60.     dec dword[m]
  61.    
  62.     mov ebp, 1
  63.     mov esi, dword[K]
  64.     add esi, 2
  65.     .ret2:
  66.     cmp ebp, esi
  67.     je .factor1
  68.     mov eax, dword[prom]
  69.     div ebp
  70.     mov dword[prom], eax
  71.     inc ebp
  72.     jmp .ret2
  73.     .factor1:
  74.    
  75.     mov ebp, 1
  76.     mov esi, dword[m]
  77.     sub esi, dword[K]
  78.     dec esi
  79.     add esi, 2
  80.     .ret3:
  81.     cmp ebp, esi
  82.     je .factor2
  83.     mov eax, dword[prom]
  84.     div ebp
  85.     mov dword[prom], eax
  86.     inc ebp
  87.     jmp .ret3
  88.     .factor2:
  89.    
  90.     mov esi, dword[res]
  91.     add esi, dword[prom]
  92.     mov dword[res], esi
  93.    
  94.     PRINT_DEC 4, [res]
  95.     NEWLINE
  96.    
  97.     mov ebx, dword[N]
  98.     sub ebx, dword[deg]
  99.    
  100.     mov dword[r], 0
  101.     mov dword[prom], 1
  102.     .ret:
  103.     mov esi, dword[prom]
  104.     cmp esi, ebx
  105.     jg .st
  106.     mov eax, dword[prom]
  107.     mov esi, 2
  108.     mul esi
  109.     mov dword[prom], eax
  110.     inc dword[r]
  111.     jmp .ret
  112.     .st:
  113.     mov eax, dword[prom]
  114.     mov esi, 2
  115.     div esi
  116.     mov dword[prom], eax
  117.     dec dword[r]
  118.    
  119.     PRINT_DEC 4, [K]
  120.     PRINT_STRING ' = K'
  121.     NEWLINE
  122.    
  123.     mov esi, dword[K]
  124.     sub esi, dword[m]
  125.     add esi, dword[r]
  126.     inc esi
  127.     mov dword[K], esi
  128.  
  129.     PRINT_DEC 4, [K]
  130.     PRINT_STRING ' = K'
  131.     NEWLINE
  132.    
  133.     mov esi, dword[r]
  134.     mov dword[m], esi
  135.    
  136.     PRINT_DEC 4, [m]
  137.     PRINT_STRING ' = m'
  138.     NEWLINE
  139.    
  140.     mov dword[N], ebx
  141.     PRINT_DEC 4, [N]
  142.     PRINT_STRING ' = N'
  143.     NEWLINE
  144.    
  145.     mov esi, dword[K]
  146.     cmp esi, dword[m]
  147.     jne .cont
  148.     inc dword[res]
  149.      .cont:
  150.     cmp esi, dword[m]
  151.     jl LOOP
  152.    
  153.     PRINT_DEC 4, [res]
  154.    
  155.     xor eax, eax
  156.     ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement