最初コミット

This commit is contained in:
2025-11-30 22:03:38 +09:00
commit 7426a775b1
8 changed files with 258 additions and 0 deletions

53
file.s Normal file
View File

@@ -0,0 +1,53 @@
section .text
load_file:
; ファイルの開く
mov rax, 5 ; sys_open
mov rdi, filename
mov rsi, 0 ; O_RDONLY
mov rdx, 0
mov rax, 499 ; sys_openat
; mov rax, 547
; mov rdi, -100 ; AT_FDCWD
; mov rsi, filename
; mov rdx, 0 ; O_RDONLY
; mov r10, 0 ; モード(見逃し)
syscall
cmp rax, 0
jl .fail
mov [filefd], rax
; ファイルサイズの受け取り
mov rax, 478 ; sys_lseek
mov rdi, [filefd]
xor rsi, rsi
mov rdx, 2 ; SEEK_END
syscall
mov [file_size], rax
; 初めからシーク
mov rax, 478
xor rsi, rsi
mov rdx, 0 ; SEEK_SET
syscall
; ファイルの全部の読み込み
mov rax, 3 ; sys_read
mov rdi, [filefd]
mov rsi, file_buf
mov rdx, [file_size]
syscall
; ファイルを閉じる
mov rax, 6 ; sys_close
mov rdi, [filefd]
syscall
xor rax, rax ; 成功
ret
.fail:
mov rax, -1
ret