# Opening a file and printing it out # C style .section .data filename: .asciz "open_file.s" .section .text .global main main: mov %rsp, %rbp mov $filename, %rdi mov $0, %rsi # O_RDONLY is 0 call open # Now we'll have a file descriptor in %rax push %rax # Let's get some memory mov $1024, %rdi call malloc # Our memory address is in rax mov (%rsp), %rdi mov %rax, %rsi mov $1024, %rdx push %rsi # The address of our memory call read mov (%rsp), %rdi # More direct than pop followed by push call puts pop %rdi call free pop %rdi call close ret