11 wrongfile_str db `unable to open file, error code: %i\n`, 0x00
15 ; reads file line by line
18 ; eax - pointer to mem
25 %define BUF_PTR 16 ; malloced array of strings
32 mov DWORD [ebp-FILE_HANDLE], 0x00
33 mov DWORD [ebp-IS_EOF], 0x00
34 mov DWORD [ebp-LINES_READ], 0x00
38 mov [ebp-BUF_PTR], eax
42 mov ebx, [ebp+_FILE_NAME]
46 mov [ebp-FILE_HANDLE], eax
48 ; check if file was open successfully
58 ; check if eof was reached
59 cmp DWORD [ebp-IS_EOF], 1
62 push DWORD [ebp-FILE_HANDLE]
71 ; make string buffer bigger
72 mov eax, DWORD [ebp-LINES_READ]
77 push DWORD [ebp-BUF_PTR]
79 mov DWORD [ebp-BUF_PTR], eax
81 ; write string to buffer
82 mov eax, DWORD [ebp-BUF_PTR]
87 add DWORD [ebp-LINES_READ], 1
94 mov ebx, [ebp-FILE_HANDLE]
97 mov eax, [ebp-BUF_PTR]
98 mov ecx, [ebp-LINES_READ]
111 ; reads a line until newline character is reached
114 ; eax: location to buffer
117 %define _FILE_HANDLE 8
118 %define CHAR_COUNT 4 ; count number of characters read
119 %define BLOCK_COUNT 8 ; number of 64 blocks we've read
120 %define STR_PTR 12 ; malloced buffer to store read string
127 mov DWORD [ebp-CHAR_COUNT], 0x00
128 mov DWORD [ebp-BLOCK_COUNT], 0x00
132 mov [ebp-STR_PTR], eax
134 push DWORD [ebp-STR_PTR]
140 cmp BYTE [ebp-CHAR_COUNT], 63 ; leave one byte for null byte
141 jne _readLine_notfull
145 ; read a single character
147 mov ebx, [ebp+_FILE_HANDLE]
148 mov ecx, [ebp-STR_PTR]
149 add ecx, [ebp-CHAR_COUNT]
155 ; mov ecx, [ebp-STR_PTR]
156 ; add ecx, [ebp-CHAR_COUNT]
161 cmp eax, 0 ; eax has zero on eof
162 jne _readLine_not_eof
168 mov eax, [ebp-STR_PTR]
169 add eax, [ebp-CHAR_COUNT]
170 cmp DWORD [eax], 0x0a
171 jne _readLine_not_newline
174 _readLine_not_newline:
176 add DWORD [ebp-CHAR_COUNT], 1
181 mov eax, DWORD [ebp-STR_PTR]