From 17adbf435e9341831aa580404d18d8caa7448ce2 Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Fri, 18 Jun 2021 14:54:04 -0400 Subject: [PATCH] reading command line arg --- makefile | 4 +++- sped.asm | 45 ++++++++++++++++++++++++++++++++++++++------- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/makefile b/makefile index d83be28..64a6613 100644 --- a/makefile +++ b/makefile @@ -1,3 +1,5 @@ +CC=gcc +CFLAGS=-m32 -no-pie -g .PHONY: clean @@ -7,7 +9,7 @@ sped.o: sped.asm nasm -f elf32 $^ -o $@ sped: sped.o - ld -m elf_i386 $^ -o $@ + $(CC) $(CFLAGS) $^ -o $@ clean: rm sped *.o diff --git a/sped.asm b/sped.asm index 6230c85..eda67b3 100644 --- a/sped.asm +++ b/sped.asm @@ -1,4 +1,8 @@ +global main +extern printf + +; macros %macro write_str 2 mov eax, 4 mov ebx, 1 @@ -8,14 +12,41 @@ %endmacro section .data - msg db "SPED - the stupidly pointless editor", 0x0a - len equ $ - msg + 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 section .text -global _start -_start: - write_str msg, len +main: + push ebp + mov ebp, esp + + ; read command line args + mov ecx, [ebp+8] + cmp ecx, 1 + jg .readFile + + ; display error msg if no file + push nofile_str + call printf mov eax, 1 - mov ebx, 42 - int 0x80 + jmp .exit + +.readFile: + + mov ebx, DWORD [ebp+12] + add ebx, 4 + push DWORD [ebx] + push readfile_str + call printf + + mov eax, 0 + jmp .exit + +.exit: + mov esp, ebp + pop ebp + ret + -- 2.20.1