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