Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Feb 9th, 2010 | Syntax: ASM (NASM) | Size: 0.96 KB | Hits: 12 | Expires: Never
Copy text to clipboard
  1. .486
  2. .model flat
  3. .data
  4.         n dd ? ; size of an array
  5.  
  6.         mx dd -1
  7.         pos dd ?
  8.         num dd 11 dup (0)
  9.        
  10. .code
  11.  
  12. _FrequentNumber proc
  13.         push ebp
  14.         mov ebp, esp
  15.        
  16.         push ebx
  17.         push ecx
  18.         push esi
  19.         push edi
  20.        
  21.         mov ebx, [ebp+8]
  22.         mov n, ebx
  23.         mov ebx, [ebp+12]
  24.        
  25.         lea edi, num
  26.        
  27.         mov ecx, n
  28.         xor esi, esi
  29. cycle:
  30.         mov eax, [ebx][esi*4]
  31.         call _Analyze
  32.         inc esi
  33.         loop cycle;
  34.        
  35.        
  36.         mov ecx, 10
  37.         mov esi, 0
  38.        
  39. findMax:
  40.         mov eax, [edi][esi*4];
  41.         cmp eax, mx
  42.        
  43.         jng fincycle
  44.        
  45.         mov mx, eax
  46.         mov pos, esi
  47. fincycle:
  48.         inc esi
  49.         loop findMax
  50.        
  51.         mov eax, pos
  52.        
  53.         pop edi
  54.         pop esi
  55.         pop ecx
  56.         pop ebx
  57.        
  58.         pop ebp
  59.         ret
  60. _FrequentNumber endp
  61.  
  62. ; The number to analyze is in eax
  63. _Analyze proc
  64.         push ebp
  65.         mov ebp, esp
  66.        
  67.         push ecx
  68.         mov ecx, 10
  69.        
  70.         push esi
  71.         push edx
  72.        
  73. cycle:
  74.         cdq
  75.         idiv ecx
  76.         mov esi, edx
  77.         inc dword ptr [edi][esi*4]
  78.         cmp eax, 0
  79.         jz finAn
  80.         jmp cycle
  81.        
  82. finAn:
  83.         pop edx
  84.         pop esi
  85.         pop ecx
  86.         pop ebp
  87.         ret
  88. _Analyze endp
  89.        
  90.        
  91.        
  92.        
  93. end