summaryrefslogtreecommitdiff
path: root/PGU/CHAP9/read_write.s
diff options
context:
space:
mode:
authorCarlos Maiolino <[email protected]>2025-07-10 22:55:07 +0200
committerCarlos Maiolino <[email protected]>2025-07-10 22:56:55 +0200
commitd98f46ce647846b0aa30b2e16a30fd4e152a1bf5 (patch)
tree267474fcc77cf20b428f6f4c7f768ca09f4cfe0e /PGU/CHAP9/read_write.s
parent869e68986aa8f69af6e7842260a68d1e5c6f796f (diff)
Add new code
Signed-off-by: Carlos Maiolino <[email protected]>
Diffstat (limited to 'PGU/CHAP9/read_write.s')
-rw-r--r--PGU/CHAP9/read_write.s62
1 files changed, 62 insertions, 0 deletions
diff --git a/PGU/CHAP9/read_write.s b/PGU/CHAP9/read_write.s
new file mode 100644
index 0000000..d574013
--- /dev/null
+++ b/PGU/CHAP9/read_write.s
@@ -0,0 +1,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