Advertisement
zzbsttt

Untitled

Apr 9th, 2021
412
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.     cmp eax, 0
  48.     je .while
  49.    
  50.     .add:
  51.     add dword[k], 1
  52.     jmp .while
  53.    
  54.    
  55.    
  56.     .end:
  57.    
  58.     sub esp, 4; 24
  59.     mov ecx, dword[k]
  60.     push ecx
  61.     push d; 32
  62.     call printf
  63.     add esp, 8; 24
  64.    
  65.     sub esp, 4; 28
  66.     push dword[f];  32
  67.     call fclose
  68.     add esp, 4; 28
  69.    
  70.     add esp, 24
  71.    
  72.     xor eax, eax
  73.     ret
Advertisement
RAW Paste Data Copied
Advertisement