12 wrongfile_str db `unable to open file, error code: %i\n`, 0x00
16 ; reads file line by line
19 ; eax - pointer to mem
26 %define BUF_PTR 16 ; malloced array of strings
33 mov DWORD [ebp-FILE_HANDLE], 0x00
34 mov DWORD [ebp-IS_EOF], 0x00
35 mov DWORD [ebp-LINES_READ], 0x00
39 mov [ebp-BUF_PTR], eax
43 mov ebx, [ebp+_FILE_NAME]
47 mov [ebp-FILE_HANDLE], eax
49 ; check if file was open successfully
59 ; check if eof was reached
60 cmp DWORD [ebp-IS_EOF], 1
63 push DWORD [ebp-FILE_HANDLE]
72 ; make string buffer bigger
73 mov eax, DWORD [ebp-LINES_READ]
78 push DWORD [ebp-BUF_PTR]
80 mov DWORD [ebp-BUF_PTR], eax
82 ; write string to buffer
83 mov eax, DWORD [ebp-BUF_PTR]
88 add DWORD [ebp-LINES_READ], 1
95 mov ebx, [ebp-FILE_HANDLE]
98 mov eax, [ebp-BUF_PTR]
99 mov ecx, [ebp-LINES_READ]
112 ; reads a line until newline character is reached
115 ; eax: location to buffer
117 ; ecx: number of chars read
119 %define _FILE_HANDLE 8
120 %define CHAR_COUNT 4 ; count number of characters read
121 %define BLOCK_COUNT 8 ; number of 64 blocks we've read
122 %define STR_PTR 12 ; malloced buffer to store read string
129 mov DWORD [ebp-CHAR_COUNT], 0x00
130 mov DWORD [ebp-BLOCK_COUNT], 0x00
134 mov [ebp-STR_PTR], eax
136 push DWORD [ebp-STR_PTR]
142 cmp BYTE [ebp-CHAR_COUNT], 63 ; leave one byte for null byte
143 jne _readLine_notfull
147 ; read a single character
149 mov ebx, [ebp+_FILE_HANDLE]
150 mov ecx, [ebp-STR_PTR]
151 add ecx, [ebp-CHAR_COUNT]
157 ; mov ecx, [ebp-STR_PTR]
158 ; add ecx, [ebp-CHAR_COUNT]
163 cmp eax, 0 ; eax has zero on eof
164 jne _readLine_not_eof
170 mov eax, [ebp-STR_PTR]
171 add eax, [ebp-CHAR_COUNT]
172 cmp DWORD [eax], 0x0a
173 jne _readLine_not_newline
176 _readLine_not_newline:
178 add DWORD [ebp-CHAR_COUNT], 1
183 mov eax, [ebp-BLOCK_COUNT]
186 add eax, [ebp-CHAR_COUNT]
189 mov eax, DWORD [ebp-STR_PTR]