|
@@ -0,0 +1,34 @@
|
|
|
+ 1 SEGMENT .text
|
|
|
+ 2 GLOBAL _start
|
|
|
+ 3 _start:
|
|
|
+ 4 00000000 B802000000 MOV RAX, 2 ; open(filename, flags)
|
|
|
+ 5 00000005 48BF- MOV RDI, filename
|
|
|
+ 5 00000007 [0000000000000000]
|
|
|
+ 6 0000000F 4831F6 XOR RSI, RSI ; set flags to 0: RD_ONLY
|
|
|
+ 7 00000012 0F05 SYSCALL
|
|
|
+ 8 00000014 4883F8FF CMP RAX, -1
|
|
|
+ 9 00000018 7433 JE err
|
|
|
+ 10 0000001A 4889C7 MOV RDI, RAX ; file descriptor
|
|
|
+ 11 0000001D 4831C0 XOR RAX, RAX ; read(fd, buf, count)
|
|
|
+ 12 00000020 48BE- MOV RSI, buf
|
|
|
+ 12 00000022 [0000000000000000]
|
|
|
+ 13 0000002A BA13000000 MOV RDX, 19 ; We read at most 19 bytes
|
|
|
+ 14 0000002F 0F05 SYSCALL
|
|
|
+ 15 00000031 4883F8FF CMP RAX, -1
|
|
|
+ 16 00000035 7416 JE err
|
|
|
+ 17 00000037 B801000000 MOV RAX, 1 ; write(fd, buf) (buf is already set from previous call)
|
|
|
+ 18 0000003C BF01000000 MOV RDI, 1 ; standard output
|
|
|
+ 19 00000041 0F05 SYSCALL
|
|
|
+ 20 00000043 B83C000000 MOV RAX, 60 ; exit(code)
|
|
|
+ 21 00000048 4831FF XOR RDI, RDI ; success
|
|
|
+ 22 0000004B 0F05 SYSCALL
|
|
|
+ 23 err:
|
|
|
+ 24 0000004D B83C000000 MOV RAX, 60 ; exit(code)
|
|
|
+ 25 00000052 BF01000000 MOV RDI, 1 ; 1 (fail)
|
|
|
+ 26 00000057 0F05 SYSCALL
|
|
|
+ 27
|
|
|
+ 28 SEGMENT .bss
|
|
|
+ 29 00000000 <res 00000014> buf RESB 20
|
|
|
+ 30
|
|
|
+ 31 SEGMENT .rodata
|
|
|
+ 32 00000000 66696C6500 filename DB "file",0
|