Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- _start:
- ; get the filename in rdi
- POP rdi ; argc
- cmp rdi, 2 ; checking number of arguments
- jne end ; if no 2 arguments - end program
- POP rdi ; argv[0] - name of program
- POP rdi ; argv[1] - file to open
- ; open the file
- mov rax, 2 ; open
- mov rsi, 0 ; read-only mode
- mov rdx, 0644o ; set flags
- syscall
- cmp RAX, 0 ; check if properly opened
- jl ending_code_one ; if not end with code one
- mov [file_descriptor], eax
- read_file:
- mov rdi, [file_descriptor] ; save file descriptor
- mov rax, 0 ; read
- mov rsi, buf ; buffer
- mov rdx, [bufsize] ; size of buffer
- syscall
- cmp rax, 4 ; check if 4 bytes read
- je check_number ; if yes procede checking input
- PUSH rax
- ; close file
- mov rax, 3
- mov rdi, [file_descriptor]
- syscall
- POP rax
- cmp rax, 0 ; end of file
- je check_conditions
- jne ending_code_one ; improper number of bytes read - code one
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement