Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. _start:
  2. ; get the filename in rdi
  3. POP rdi ; argc
  4. cmp rdi, 2 ; checking number of arguments
  5. jne end ; if no 2 arguments - end program
  6. POP rdi ; argv[0] - name of program
  7. POP rdi ; argv[1] - file to open
  8.  
  9. ; open the file
  10. mov rax, 2 ; open
  11. mov rsi, 0 ; read-only mode
  12. mov rdx, 0644o ; set flags
  13. syscall
  14. cmp RAX, 0 ; check if properly opened
  15. jl ending_code_one ; if not end with code one
  16. mov [file_descriptor], eax
  17.  
  18.  
  19. read_file:
  20. mov rdi, [file_descriptor] ; save file descriptor
  21. mov rax, 0 ; read
  22. mov rsi, buf ; buffer
  23. mov rdx, [bufsize] ; size of buffer
  24. syscall
  25. cmp rax, 4 ; check if 4 bytes read
  26. je check_number ; if yes procede checking input
  27. PUSH rax
  28. ; close file
  29. mov rax, 3
  30. mov rdi, [file_descriptor]
  31. syscall
  32. POP rax
  33. cmp rax, 0 ; end of file
  34. je check_conditions
  35. jne ending_code_one ; improper number of bytes read - code one
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement