-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntime.asm
More file actions
73 lines (67 loc) · 1.08 KB
/
runtime.asm
File metadata and controls
73 lines (67 loc) · 1.08 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
70
71
72
73
bits 32
global _start;
putc:
push ebx
push ecx
push edx
mov ebx, CHAR_BUF
mov [ebx], al
mov eax, 4
mov ebx, 1
mov ecx, CHAR_BUF
mov edx, 1
int 0x80
pop edx
pop ecx
pop ebx
ret
BUF_CHAR: db 0x90
print_num_signed:
test eax, eax
jz zero
jns _ns
push eax
mov al, '-'
call putc
pop eax
neg eax
_ns:
xor ecx, ecx
mov ebx, 10
_n0:
test eax, eax
jz _n1
xor edx, edx
div ebx
add edx, '0'
mov esi, NUM_BUF
mov byte [esi+ecx], dl
inc ecx
jmp _n0
_n1:
dec ecx
add esi, ecx
inc ecx
_n2:
mov al, byte [esi]
call putc
dec esi
dec ecx
jnz _n2
ret
zero:
mov al, '0'
call putc
ret
print_num_nl:
call print_num_signed
mov eax, 0xa
call putc
ret
exit:
mov eax, 1
xor ebx, ebx
int 0x80
section .data
NUM_BUF: times 16 db 0
CHAR_BUF: db 0