1234567891011121314151617181920212223242526272829303132 |
- SEGMENT .text
- GLOBAL _start
- _start:
- MOV RAX, 2 ; open(filename, flags)
- MOV RDI, filename
- XOR RSI, RSI ; set flags to 0: RD_ONLY
- SYSCALL
- CMP RAX, -1
- JE err
- MOV RDI, RAX ; file descriptor
- XOR RAX, RAX ; read(fd, buf, count)
- MOV RSI, buf
- MOV RDX, 19 ; We read at most 19 bytes
- SYSCALL
- CMP RAX, -1
- JE err
- MOV RAX, 1 ; write(fd, buf) (buf is already set from previous call)
- MOV RDI, 1 ; standard output
- SYSCALL
- MOV RAX, 60 ; exit(code)
- XOR RDI, RDI ; success
- SYSCALL
- err:
- MOV RAX, 60 ; exit(code)
- MOV RDI, 1 ; 1 (fail)
- SYSCALL
-
- SEGMENT .bss
- buf RESB 20
- SEGMENT .rodata
- filename DB "file",0
|