X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=sped.asm;h=110bf98378f1bd5e012172bb48a69c768c38c04b;hb=fb894149783dd18e6ecf1271153193a342e80433;hp=6230c852604e4d959e9a909669573042e4b17b32;hpb=4c9d6b68e0b493e23969b79e96457b68cfed8895;p=sped.git diff --git a/sped.asm b/sped.asm index 6230c85..110bf98 100644 --- a/sped.asm +++ b/sped.asm @@ -1,21 +1,48 @@ +; sped - the stupidly pointless editor +; written by pinosaur -%macro write_str 2 - mov eax, 4 - mov ebx, 1 - mov ecx, %1 - mov edx, %2 - int 0x80 -%endmacro +%include "fileutils.S" + +global main +extern printf section .data - msg db "SPED - the stupidly pointless editor", 0x0a - len equ $ - msg + banner_str db `SPED - the stupidly pointless editor\n`, 0x00 + nofile_str db `no file provided\n`, 0x00 section .text -global _start -_start: - write_str msg, len +main: + %define _ARGC 8 + %define _ARGV 12 + + push ebp + mov ebp, esp + ; read command line args + mov ecx, [ebp+_ARGC] + cmp ecx, 1 + jg _main_existing + + ; display error msg if no file + push nofile_str + call printf mov eax, 1 - mov ebx, 42 - int 0x80 + jmp _main_exit + + _main_existing: + mov ebx, DWORD [ebp+_ARGV] + add ebx, 4 ; first user arg is filename + push DWORD [ebx] + call readFile + + mov eax, 0 + jmp _main_exit + + _main_exit: + %undef _ARGC + %undef _ARGV + + mov esp, ebp + pop ebp + ret +