.include "record-def.s" .include "linux.s" # Read function # Reads a record from the file descriptor # and writes it into the buffer passed # STACK VARS - Used for both read and write functions. They don't share the # location, but the arguments are passed in the same position # for both, so, no need to create different location vars. .equ ST_BUFFER, 16 # Ret address is at %rsp+8 .equ ST_FILEDES, 24 .section .text .globl read_record .type read_record, @function read_record: pushq %rbp movq %rsp, %rbp # READ A RECORD pushq %rdi movq ST_FILEDES(%rbp), %rdi movq ST_BUFFER(%rbp), %rsi movq $RECORD_SIZE, %rdx movq $SYS_READ, %rax syscall # NOTE: %rax has the return value, which we will give back # to our caller popq %rdi movq %rbp, %rsp popq %rbp ret .globl write_record .type write_record, @function write_record: pushq %rbp movq %rsp, %rbp # WRITE A RECORD pushq %rdi movq ST_FILEDES(%rbp), %rdi movq ST_BUFFER(%rbp), %rsi movq $RECORD_SIZE, %rdx movq $SYS_WRITE, %rax syscall # NOTE: %rax has the return value, which we will give back # to our caller popq %rdi movq %rbp, %rsp popq %rbp ret