This repository has been archived on 2026-05-26. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
http/file.s
2025-11-30 22:03:38 +09:00

54 lines
1.1 KiB
ArmAsm

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