46 lines
1.2 KiB
NASM
46 lines
1.2 KiB
NASM
section .data
|
|
file_path db 'test.txt', 0 ; File path
|
|
message db 'Hello, World from KatauOS!', 10, 0 ; Message with newline
|
|
message_len equ $ - message - 1 ; Length excluding null terminator
|
|
|
|
section .bss
|
|
buffer resb 256 ; Buffer for reading file content
|
|
read_count resd 1 ; Store bytes read count
|
|
|
|
section .text
|
|
global _start
|
|
|
|
_start:
|
|
; Reopen file for reading
|
|
mov eax, 5 ; sys_open
|
|
mov ebx, file_path
|
|
mov ecx, 0 ; O_RDONLY
|
|
mov edx, 0 ; Mode (unused)
|
|
int 0x80
|
|
mov edi, eax ; Save new descriptor
|
|
|
|
; Read file content
|
|
mov eax, 3 ; sys_read
|
|
mov ebx, edi
|
|
mov ecx, buffer
|
|
mov edx, 256
|
|
int 0x80
|
|
mov [read_count], eax ; Save bytes read count
|
|
|
|
; Write to stdout
|
|
mov eax, 4 ; sys_write
|
|
mov ebx, 1 ; stdout
|
|
mov ecx, buffer
|
|
mov edx, [read_count] ; Use actual bytes read
|
|
int 0x80
|
|
|
|
; Close file
|
|
mov eax, 6 ; sys_close
|
|
mov ebx, edi
|
|
int 0x80
|
|
|
|
; Exit
|
|
mov eax, 1 ; sys_exit
|
|
xor ebx, ebx ; Return 0
|
|
int 0x80
|