-
Notifications
You must be signed in to change notification settings - Fork 0
/
stdlib.asm
81 lines (57 loc) · 1.05 KB
/
stdlib.asm
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
70
71
72
73
74
75
76
77
78
79
80
81
_stdcurbrk:
push ebx ; protecc
xor ebx, ebx ; optimize mov ebx, 0 for size
mov eax, 45
int 0x80
pop ebx
ret
_stdincbrk:
push ecx
push ebx ; protect registers while working
mov ecx, ebx
xor ebx, ebx ; optimize mov ebx, 0 for size
mov eax, 45
int 0x80
add eax, ecx
mov ebx, eax
mov eax, 45
int 0x80
pop ebx
pop ecx ; re-fill registers with their values
ret
_stddecbrk:
push ecx
push ebx ; protect registers while working
mov ecx, ebx
xor ebx, ebx ; optimize mov ebx, 0 for size
mov eax, 45
int 0x80
sub eax, ecx
mov ebx, eax
mov eax, 45
int 0x80
pop ebx
pop ecx ; re-fill registers with their values
ret
_stdstrlen:
mov edx, ecx ; needs to be passed ecx: string
.nextchar:
cmp byte [edx], 0
jz .done
inc edx
jmp .nextchar
.done:
sub edx, ecx
ret ; returns in edx
_stdprint:
push ebx ; protect ebx
xor ebx, ebx ; needs to be passed edx and ecx
inc ebx ; set fd to stdout
mov eax, 4 ; syscall #
int 0x80
pop ebx ; re-fill
ret
_stdexit:
xor eax,eax ; lowest bytes used to get to
inc eax ; 1 in eax, this uses 3 while
int 0x80 ; mov uses 5