final clean up
[sped.git] / sped.asm
1 ; sped - the stupidly pointless editor
2 ; written by pinosaur
3 ; sped.asm: main file
4
5 %include "macros.S"
6
7 extern printf
8
9 extern readFile
10 extern repl
11
12 global main
13
14 section .data
15     banner_str db `SPED - the stupidly pointless editor\n`, 0x00
16     nofile_str db `no file provided.\n`, 0x00
17     readlines_str db `opened file with %i lines.\n`, 0x00
18
19 section .text
20 main:
21     %define _ARGC 8
22     %define _ARGV 12
23
24     %define BUFFER          4
25     %define BUFFER_LINES    8
26     %define BUFFER_FILENAME 12
27
28     push ebp
29     mov ebp, esp
30
31     sub esp, 12
32
33     ; read command line args
34     mov ecx, [ebp+_ARGC]
35     cmp ecx, 1
36     jg _main_existing
37     
38     ; display error msg if no file
39     push nofile_str
40     call printf
41     mov eax, 1
42     jmp _main_exit
43
44     _main_existing:
45     mov ebx, DWORD [ebp+_ARGV]
46     add ebx, 4 ; first user arg is filename
47     mov ebx, [ebx]
48     mov [ebp-BUFFER_FILENAME], ebx
49
50     push DWORD [ebp-BUFFER_FILENAME]
51     call readFile
52
53     mov [ebp-BUFFER], eax
54     mov [ebp-BUFFER_LINES], ecx
55
56     push DWORD [ebp-BUFFER_LINES]
57     push readlines_str
58     call printf
59
60     push DWORD [ebp-BUFFER]
61     push DWORD [ebp-BUFFER_LINES]
62     push DWORD [ebp-BUFFER_FILENAME]
63     call repl
64
65     mov eax, 0
66     jmp _main_exit
67
68     _main_exit:
69
70     ; free string array
71
72     %undef _ARGC
73     %undef _ARGV
74     %undef BUFFER
75     %undef BUFFER_LINES
76     %undef BUFFER_FILENAME
77
78     mov esp, ebp
79     pop ebp
80     ret
81