reading command line arg
[sped.git] / sped.asm
1
2 global main
3 extern printf
4
5 ; macros
6 %macro write_str 2
7     mov eax, 4
8     mov ebx, 1
9     mov ecx, %1
10     mov edx, %2
11     int 0x80
12 %endmacro
13
14 section .data
15     banner_str db `SPED - the stupidly pointless editor\n`, 0x00
16     readfile_str db `reading file %s\n`, 0x00
17     nofile_str db `no file provided\n`, 0x00
18     argcount_str db `there are %d args\n`, 0x00
19
20 section .text
21 main:
22     push ebp
23     mov ebp, esp
24
25     ; read command line args
26     mov ecx, [ebp+8]
27
28     cmp ecx, 1
29     jg .readFile
30     
31     ; display error msg if no file
32     push nofile_str
33     call printf
34     mov eax, 1
35     jmp .exit
36
37 .readFile:
38
39     mov ebx, DWORD [ebp+12]
40     add ebx, 4
41     push DWORD [ebx]
42     push readfile_str
43     call printf
44
45     mov eax, 0
46     jmp .exit
47
48 .exit:
49     mov esp, ebp
50     pop ebp
51     ret
52