Advertisement
zzbsttt

Untitled

Apr 9th, 2021
253
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 "D:\assembler\5con\data.txt", 0
  8. k dd 0
  9. f dd 0
  10.  
  11. section .bss
  12. x resd 1
  13.  
  14. section .text
  15.  
  16. CEXTERN fopen
  17. CEXTERN fclose
  18. CEXTERN fscanf
  19. EXTERN printf
  20.  
  21. global CMAIN
  22. CMAIN:
  23.     mov ebp, esp; for correct debugging
  24.     sub esp, 4; 4 + 4 = 8
  25.    
  26.     push r
  27.     push in1; 16
  28.     call fopen
  29.     add esp, 8; 8
  30.    
  31.     mov dword[f], eax; esi = f
  32.    
  33.     .while:
  34.     sub esp, 12 ; 20
  35.     push x
  36.     push d
  37.     push dword[f]; 32
  38.     call fscanf
  39.     add esp, 12; 20
  40.    
  41.     cmp eax, 1
  42.     je .add
  43.    
  44.     cmp eax, -1
  45.     je .end
  46.    
  47.     .add:
  48.     add dword[k], 1
  49.     jmp .while
  50.    
  51.    
  52.    
  53.     .end:
  54.    
  55.     sub esp, 4; 24
  56.     mov ecx, dword[k]
  57.     push ecx
  58.     push d; 32
  59.     call printf
  60.     add esp, 8; 24
  61.    
  62.     sub esp, 4; 28
  63.     push dword[f];  32
  64.     call fclose
  65.     add esp, 4; 28
  66.    
  67.     add esp, 24
  68.    
  69.     xor eax, eax
  70.     ret
Advertisement
RAW Paste Data Copied
Advertisement