1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
.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
|