1 ; sped - the stupidly pointless editor
21 banner_str db `SPED - the stupidly pointless editor\n`, 0x00
22 readfile_str db `reading file %s\n`, 0x00
23 nofile_str db `no file provided\n`, 0x00
24 argcount_str db `there are %d args\n`, 0x00
25 wrongfile_str db `unable to open file, error code: %i\n`, 0x00
26 char_str db `read this char: %i\n`, 0x00
27 printfint_str db `int: %i\n`, 0x00
37 ; read command line args
42 ; display error msg if no file
49 mov ebx, DWORD [ebp+_ARGV]
69 ; reads file line by line
72 ; eax - pointer to mem
83 mov DWORD [ebp-FILE_HANDLE], 0x00
87 mov ebx, [ebp+_FILE_NAME]
91 mov [ebp-FILE_HANDLE], eax
93 ; check if file was open successfully
102 push DWORD [ebp-FILE_HANDLE]
113 mov ebx, [ebp-FILE_HANDLE]
124 ; reads a line until newline character is reached
127 ; eax: location to buffer
130 %define _FILE_HANDLE 8
131 %define CHAR_COUNT 4 ; count number of characters read
132 %define BLOCK_COUNT 8 ; number of 64 blocks we've read
133 %define STR_PTR 12 ; malloced buffer to store read string
140 mov DWORD [ebp-CHAR_COUNT], 0x00
141 mov DWORD [ebp-BLOCK_COUNT], 0x00
145 mov [ebp-STR_PTR], eax
147 push DWORD [ebp-STR_PTR]
153 cmp BYTE [ebp-CHAR_COUNT], 63 ; leave one byte for null byte
154 jne _readLine_notfull
158 ; read a single character
160 mov ebx, [ebp+_FILE_HANDLE]
161 mov ecx, [ebp-STR_PTR]
162 add ecx, [ebp-CHAR_COUNT]
168 ; mov ecx, [ebp-STR_PTR]
169 ; add ecx, [ebp-CHAR_COUNT]
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:
183 mov eax, [ebp-STR_PTR]
184 add eax, [ebp-CHAR_COUNT]
185 cmp DWORD [eax], 0x05
186 jne _readLine_not_eof
191 add DWORD [ebp-CHAR_COUNT], 1
196 mov eax, DWORD [ebp-STR_PTR]