-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusercode.asm
More file actions
69 lines (58 loc) · 1.7 KB
/
usercode.asm
File metadata and controls
69 lines (58 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
[bits 64]
section .data
text: db "idk", 3, 0
filename: db "hello.txt", 9, 0
path: db "test.txt", 0
section .bss
buf: resb 69
section .text
loop:
; open file
mov rax, 2 ; open syscall
lea rdi, [rel path] ; path to file
mov rsi, 0 ; flags (read-only)
mov rdx, 0 ; mode
int 0x69
; check if open was successful (assuming negative return = error)
cmp rax, 0
jl exit_error ; jump to error handling if open failed
; save file descriptor
mov r8, rax ; save fd in r8
; read from file
mov rax, 0 ; read syscall
mov rdi, r8 ; use saved file descriptor
lea rsi, [rel buf] ; buffer to read into
mov rdx, 69 ; number of bytes to read
int 0x69
; save number of bytes read
mov r9, rax ; save bytes read count
; print buffer contents
mov rax, 8 ; print syscall
lea rdi, [rel buf] ; buffer to print
mov rsi, r9 ; use actual bytes read, not fixed 69
int 0x69
; close file (assuming syscall 3 for close)
mov rax, 3 ; close syscall (you may need to check your syscall numbers)
mov rdi, r8 ; file descriptor to close
int 0x69
; get framebuffer address
xor rax, rax
mov rax, 10
int 0x69 ; rax = framebuffer pointer
; make screen black
mov rdi, rax
mov rcx, rbx ; fb size saved in rbx
shr rcx, 3 ; rcx = number of qwords
xor rax, rax ; black color
loop_start:
mov [rdi], rax
add rdi, 8
dec rcx
jnz loop_start
; exit cleanly
mov rax, 9 ; exit syscall
int 0x69
exit_error:
; handle open failure
mov rax, 9 ; exit syscall
int 0x69