summaryrefslogtreecommitdiff
path: root/epilogue.snippet.asm
blob: d1c44a1bc9ef86aad12acd4edbc2c9cf8a905660 (plain)
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
	nop

	mov rdi, [buf]  ; EPILOGUE
	call _free

%ifdef OUTPUT_LAST_CELL
	lea rdi, [strbuf64] ; snprintf(strbuf64,64,LCRformatstr,maxp-buf)
	mov esi, 64
	lea rdx, [LCRformatstr]
	mov rcx, qword [maxp]
	sub rcx, qword [buf]
	call _snprintf

	mov edi, 2
	lea rsi, [strbuf64]
	mov edx, eax
	call _write
%endif

%ifdef HEATMAPFNAME
	lea rdi, [HMfname]
	lea rsi, [HMfmode]
	call _fopen
	cmp rax, 0
	jz fopenerror
	mov r13, rax ;file pointer

	mov ebx, 0 ;loop counter
hmloop:
	mov rdi, r13
	lea rsi, [HMformatstr]
	mov edx, ebx
	mov ecx, dword [r12+4*rbx]
	call _fprintf

	inc ebx
	cmp ebx, SOURCE_LENGTH
	jl hmloop

	mov rdi, r13
	call _fclose
%endif

	xor eax, eax

mainend:
	pop r13
	pop r13
	pop r12
	pop rbx
	mov rsp, rbp
	pop rbp
	ret

nomem:
	mov edi, 2
	lea rsi, [nomemstr]
	mov rdx, nomemstr.len
	call _write
	mov eax, 1
	jmp mainend

fopenerror:
	lea rdi, [fopenstr]
	call _perror
	mov eax, 1
	jmp mainend


section .data
sectalign 8

nomemstr: db "Out of memory!"
.len: equ $-nomemstr

fopenstr: db "fopen", 0

%ifdef OUTPUT_LAST_CELL
	LCRformatstr: db "Last cell reached: %d", 10, 0

	align 8, db 0
	maxp: dq 0
%endif

%ifdef HEATMAPFNAME
	HMfname: db HEATMAPFNAME
	HMfmode: db "w", 0
	HMformatstr: db "%d %d", 10, 0
%endif


section .bss
sectalign 8

buf: resq 1

strbuf64: resb 64