aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Cunningham <cc@localhost>2024-07-13 23:27:06 -0700
committerChristian Cunningham <cc@localhost>2024-07-13 23:27:06 -0700
commit28fbc837eaff40b0f992233e583f8352f13dddfe (patch)
tree6f0bdf26310217cf9770162156799f9da43a241c
parent0a4608eb004ebe720068cc538158bda3156948f2 (diff)
Dynamic allocation for file data!
-rw-r--r--file.inc17
-rw-r--r--main.asm28
2 files changed, 41 insertions, 4 deletions
diff --git a/file.inc b/file.inc
index 3415c4f..bfbf8e0 100644
--- a/file.inc
+++ b/file.inc
@@ -1,6 +1,7 @@
%ifndef FILE_INC
%define FILE_INC
-%define FBUF_DEFAULT_SIZE 1024*32
+%define FBUF_DEFAULT_SIZE 16
+%define FBUF_ALLOC_SIZE 1024*32
%ifndef SYS_INC
%include "sys.inc"
%endif
@@ -96,6 +97,20 @@ ffopen:
pop rbp
ret
+ffread:
+ push rbp
+ mov rbp, rsp
+ mov rdi, [rax + fd]
+ mov rdi, [rdi]
+ mov rsi, [rax + buffer]
+ mov rdx, [rax + size]
+ mov rax, SYS_READ
+ syscall
+ ;;
+ mov rsp, rbp
+ pop rbp
+ ret
+
print_filedata:
push rbp
mov rbp, rsp
diff --git a/main.asm b/main.asm
index fbddef4..9a2f7ee 100644
--- a/main.asm
+++ b/main.asm
@@ -70,20 +70,42 @@ _main:
m_bind data_to_zstring_mh
m_call print_zstring
+ ;; m_call ffopen, rel m_test_file
+ ;; flen test_file
+ ;; push rax
+ ;; m_return rel m_test_mdots
+ ;; m_bind data_to_zstring_md
+ ;; m_call print_zstring
+ ;; pop rax
+ ;; cmp rax, FBUF_DEFAULT_SIZE
+ ;; ja .error.exit
+ ;; fbegin test_file
+ ;; fread test_file
+ ;; fclose test_file
+
+ ;; m_call print_filedata, rel m_test_file
+
+ alloc FBUF_ALLOC_SIZE
+ mov rbx, rax
m_call ffopen, rel m_test_file
+ mov [rel test_file_filedata + buffer], rbx
+ mov qword [rel test_file_filedata + size], FBUF_ALLOC_SIZE
flen test_file
push rax
m_return rel m_test_mdots
m_bind data_to_zstring_md
m_call print_zstring
pop rax
- cmp rax, FBUF_DEFAULT_SIZE
+ cmp rax, FBUF_ALLOC_SIZE
ja .error.exit
fbegin test_file
- fread test_file
+ lea rax, [rel test_file_filedata]
+ call ffread
fclose test_file
- m_call print_filedata, rel m_test_file
+ mov rax, [rel test_file_filedata + buffer]
+ call print_zstring
+ free rbx, FBUF_ALLOC_SIZE
exit_prog