-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheditor.asm
188 lines (143 loc) · 3 KB
/
editor.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
; Siddharth Rajan
; CSC 21000
; Project 2: Text Editor
; Program to implement basic text editor, open, read, write, and save a file.
.model tiny
.data
WS equ 20h
filename db 'txt3.txt', 0
handle dw 0
buffer db 2000 DUP(?)
edit dw 0
.code
org 100h
start:
mov ah,06h ; set background color
mov al, 00h
xor cx, cx
mov dx,184fh
mov bh,4eh
int 10h
mov ah, 3
int 10h
mov ah, 02h
mov dh, 0 ; set initial cursor for reading/writing buffer
mov dl, 0
mov bh, 0
int 10h
mov ah, 3dh ; open file for reading (txt3)
mov al, 0
mov dx, offset filename
int 21h
mov handle, ax
mov ah, 3fh ; read from file (txt3)
mov bx, handle
mov cx, 2000
mov dx, offset buffer
int 21h
mov dx, offset buffer
add dx, ax
mov bx, dx
mov byte ptr [bx], '$'
mov dx, offset buffer ; print data read (txt3)
mov ah, 9
int 21h
mov ah, 3
int 10h
mov ah, 02h
mov dh, 0 ; set cursor at beginning again
mov dl, 0
mov bh, 0
int 10h
mov ah, 3eh ; close file (txt3)
mov bx, handle
int 21h
mov si, offset buffer ; user inputs
input:
mov ah, 0
int 16h
cmp ah, 4Dh ; right Arrow key (key code)
je right
cmp ah, 4Bh ; left Arrow key (key code)
je left
cmp al, 8 ; backspace key (ascii)
je erase
cmp al, 27 ; escape key (ascii)
je exit
cmp al, 9 ; tab key (ascii)
je tab
mov [si], al ; anything else, write in buffer
inc si
mov edit, 1
mov ah,0ah ; print character in buffer
mov cx,1
mov bh,0
int 10h
add dl, 1
mov ah, 2
mov bh, 0
int 10h
jmp input
right:
inc si
mov ah, 3
int 10h
mov ah, 2 ; move cursor right one space
add dl, 1
int 10h
jmp input
left:
dec si
mov ah, 3
int 10h
mov ah, 2 ; move cursor left one space
sub dl, 1
int 10h
jmp input
tab:
mov ah, 3
int 10h
mov ah, 2 ; move cursor right four spaces
add dl, 4
int 10h
inc si
inc si
inc si
inc si
jmp input
erase:
mov ah,02h
sub dl, 1
mov bh,0
int 10h
mov ah,0ah
mov al,WS
mov cx,1
int 10h
dec si
mov al, WS
mov [si], al
mov edit, 1
jmp input
exit:
cmp edit, 0
je close
mov ah, 3dh ; open file for writing (txt3)
mov al, 1
mov dx, offset filename
int 21h
mov handle, ax
mov ah, 40h
mov bx, handle ; write to file (txt3)
mov cx, word ptr 2000
mov dx, offset buffer
int 21h
mov ah, 3eh ; close file (txt3)
mov bx, handle
int 21h
close:
mov ax, 003h
int 10h
mov ah, 4ch ; quit
int 21h
end start