Advertisement
zzbsttt

Untitled

Apr 9th, 2021
276
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. %include "io.inc"
  2.  
  3. section .data
  4. r db "r", 0
  5. s db "%s", 0
  6. d db "%d", 0
  7. in1 db "data.txt", 0
  8. k dd 0
  9.  
  10. section .bss
  11. x resd 1
  12.  
  13. section .text
  14.  
  15. CEXTERN fopen
  16. CEXTERN fclose
  17. CEXTERN fscanf
  18. EXTERN printf
  19.  
  20. global CMAIN
  21. CMAIN:
  22.     mov ebp, esp; for correct debugging
  23.     sub esp, 4; 4 + 4 = 8
  24.    
  25.     push r
  26.     push in1; 16
  27.     call fopen
  28.     add esp, 8; 8
  29.    
  30.     mov esi, eax; esi = f
  31.    
  32.     .while:
  33.     sub esp, 12 ; 20
  34.     push x
  35.     push d
  36.     push dword[esi]; 32
  37.     call fscanf
  38.     add esp, 12; 20
  39.    
  40.     cmp eax, 1
  41.     je .add
  42.    
  43.     cmp eax, -1
  44.     je .end
  45.    
  46.     .add:
  47.     add dword[k], 1
  48.     jmp .while
  49.    
  50.    
  51.    
  52.     .end:
  53.    
  54.     sub esp, 4; 24
  55.     mov ecx, dword[k]
  56.     push ecx
  57.     push d; 32
  58.     call printf
  59.     add esp, 8; 24
  60.    
  61.     sub esp, 4; 28
  62.     push dword[esi]; 32
  63.     call fclose
  64.     add esp, 4; 28
  65.    
  66.     add esp, 28
  67.    
  68.     xor eax, eax
  69.     ret
Advertisement
RAW Paste Data Copied
Advertisement