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, [ebp-LINES_READ]
86 add eax, DWORD [ebp-BUF_PTR]
92 add DWORD [ebp-LINES_READ], 1
99 mov ebx, [ebp-FILE_HANDLE]
102 mov eax, [ebp-BUF_PTR]
103 mov ecx, [ebp-LINES_READ]
116 ; reads a line until newline character is reached
119 ; eax: location to buffer
121 ; ecx: number of chars read
123 %define _FILE_HANDLE 8
124 %define CHAR_COUNT 4 ; count number of characters read
125 %define BLOCK_COUNT 8 ; number of 64 blocks we've read
126 %define STR_PTR 12 ; malloced buffer to store read string
133 mov DWORD [ebp-CHAR_COUNT], 0x00
134 mov DWORD [ebp-BLOCK_COUNT], 0x00
138 mov [ebp-STR_PTR], eax
140 push DWORD [ebp-STR_PTR]
146 cmp BYTE [ebp-CHAR_COUNT], 63 ; leave one byte for null byte
147 jne _readLine_notfull
151 ; read a single character
153 mov ebx, [ebp+_FILE_HANDLE]
154 mov ecx, [ebp-STR_PTR]
155 add ecx, [ebp-CHAR_COUNT]
161 ; mov ecx, [ebp-STR_PTR]
162 ; add ecx, [ebp-CHAR_COUNT]
167 cmp eax, 0 ; eax has zero on eof
168 jne _readLine_not_eof
174 mov eax, [ebp-STR_PTR]
175 add eax, [ebp-CHAR_COUNT]
176 cmp DWORD [eax], 0x0a
177 jne _readLine_not_newline
180 _readLine_not_newline:
182 add DWORD [ebp-CHAR_COUNT], 1
187 mov eax, [ebp-BLOCK_COUNT]
190 add eax, [ebp-CHAR_COUNT]
193 mov eax, DWORD [ebp-STR_PTR]
204 ; writes contents of string array into file
205 ; arg: filename, string array