X-Git-Url: https://git.danieliu.xyz/?p=sped.git;a=blobdiff_plain;f=sped.asm;h=a14dbd4867bbad6ea69eedc36680cd8a7bb01e19;hp=110bf98378f1bd5e012172bb48a69c768c38c04b;hb=89732d399de9007aaf2894b0c637e8cfb9ed47ac;hpb=fb894149783dd18e6ecf1271153193a342e80433 diff --git a/sped.asm b/sped.asm index 110bf98..a14dbd4 100644 --- a/sped.asm +++ b/sped.asm @@ -2,22 +2,40 @@ ; written by pinosaur %include "fileutils.S" +%include "repl.S" -global main extern printf +global main + +; macros +%macro write_str 2 + mov eax, 4 + mov ebx, 1 + mov ecx, %1 + mov edx, %2 + int 0x80 +%endmacro + section .data banner_str db `SPED - the stupidly pointless editor\n`, 0x00 nofile_str db `no file provided\n`, 0x00 + readlines_str db `opened file with %i lines\n`, 0x00 section .text main: %define _ARGC 8 %define _ARGV 12 + %define BUFFER 4 + %define BUFFER_LINES 8 + %define BUFFER_FILENAME 12 + push ebp mov ebp, esp + sub esp, 12 + ; read command line args mov ecx, [ebp+_ARGC] cmp ecx, 1 @@ -32,15 +50,36 @@ main: _main_existing: mov ebx, DWORD [ebp+_ARGV] add ebx, 4 ; first user arg is filename - push DWORD [ebx] + mov ebx, [ebx] + mov [ebp-BUFFER_FILENAME], ebx + + push DWORD [ebp-BUFFER_FILENAME] call readFile + mov [ebp-BUFFER], eax + mov [ebp-BUFFER_LINES], ecx + + push DWORD [ebp-BUFFER_LINES] + push readlines_str + call printf + + push DWORD [ebp-BUFFER] + push DWORD [ebp-BUFFER_LINES] + push DWORD [ebp-BUFFER_FILENAME] + call repl + mov eax, 0 jmp _main_exit _main_exit: + + ; free string array + %undef _ARGC %undef _ARGV + %undef BUFFER + %undef BUFFER_LINES + %undef BUFFER_FILENAME mov esp, ebp pop ebp