X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;ds=sidebyside;f=sped.asm;h=a14dbd4867bbad6ea69eedc36680cd8a7bb01e19;hb=89732d399de9007aaf2894b0c637e8cfb9ed47ac;hp=eda67b319c0ed0c03fbe20f546e5b2bf76db4752;hpb=17adbf435e9341831aa580404d18d8caa7448ce2;p=sped.git diff --git a/sped.asm b/sped.asm index eda67b3..a14dbd4 100644 --- a/sped.asm +++ b/sped.asm @@ -1,7 +1,13 @@ +; sped - the stupidly pointless editor +; written by pinosaur + +%include "fileutils.S" +%include "repl.S" -global main extern printf +global main + ; macros %macro write_str 2 mov eax, 4 @@ -13,39 +19,68 @@ extern printf section .data banner_str db `SPED - the stupidly pointless editor\n`, 0x00 - readfile_str db `reading file %s\n`, 0x00 nofile_str db `no file provided\n`, 0x00 - argcount_str db `there are %d args\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 - ; read command line args - mov ecx, [ebp+8] + sub esp, 12 + ; read command line args + mov ecx, [ebp+_ARGC] cmp ecx, 1 - jg .readFile + jg _main_existing ; display error msg if no file push nofile_str call printf mov eax, 1 - jmp .exit + jmp _main_exit + + _main_existing: + mov ebx, DWORD [ebp+_ARGV] + add ebx, 4 ; first user arg is filename + mov ebx, [ebx] + mov [ebp-BUFFER_FILENAME], ebx -.readFile: + push DWORD [ebp-BUFFER_FILENAME] + call readFile - mov ebx, DWORD [ebp+12] - add ebx, 4 - push DWORD [ebx] - push readfile_str + 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 .exit + jmp _main_exit + + _main_exit: + + ; free string array + + %undef _ARGC + %undef _ARGV + %undef BUFFER + %undef BUFFER_LINES + %undef BUFFER_FILENAME -.exit: mov esp, ebp pop ebp ret