-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab3.asm
159 lines (130 loc) · 4.06 KB
/
lab3.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
; Antanas Vasiliauskas 3 grupė, 3 užduotis, 18 variantas
%include 'yasmmac.inc'
org 100h
section .text
Pradzia:
jmp Nustatymas
Senas_I88:
dw 0000, 0000
input_handle:
dw 0000
output_handle:
dw 0000
tekstas:
db 'Baigiame',0Dh, 0Ah, '$'
buffer_byte:
db 'a'
; Open input file // procFOpenForReading, I: ds:dx - ASCIIZ pavadinimas | O: bx - failo deskriptorius, jei CF == 0, CF = 1, jeigu klaida
; Open output file // procFOpenForWriting, I: ds:dx - ASCIIZ pavadinimas | O: bx - failo deskriptorius, jei CF == 0, CF = 1, jeigu klaida
; while !EOF and !0x0A and !0x0D
; read char // procFGetChar, I: bx - failo deskriptorius | O: ax - ar nuskaitė (0 ar 1), cl - baitas, CF == 1, jeigu klaida
; write char // procFPutChar, I: bx - failo deskriptorius, al - rašomas baitas | O: ax - kiek faktiškai įrašė
; Close files // procFClose, I: bx - failo deskriptorius
; iret
Naujas_I88:
macPushAll
push ds
push es
pop ds
call procFOpenForReading
; Patikriname ar sekmingai atidare faila
mov ax, 0000
adc ax, 0
cmp ax, 0001
jnz Mark1
push ds
push cs
pop ds
macPutString "Nepavyko atidaryti duomenu failo.", crlf, '$'
pop ds
pop ds
jmp return
Mark1:
mov [cs:input_handle], bx
pop ds
mov dx, cx
; Create file
mov cx, 0
mov ah, 3Ch
int 0x21
call procFOpenForWriting
; Patikriname ar sekmingai atidare faila
mov ax, 0000
adc ax, 0
cmp ax, 0001
jnz Mark2
push ds
push cs
pop ds
macPutString "Nepavyko atidaryti rezultatu failo.", crlf, '$'
pop ds
jmp return
Mark2:
mov [cs:output_handle], bx
;; Skaitom ir rasom i faila po viena simboli
push ds
push cs
pop ds
ReadWriteLoop:
mov bx, [cs:input_handle]
push dx
push cx
mov cx, 1
mov dx, buffer_byte
mov ah, 0x3F
int 0x21
pop cx
pop dx
cmp ax, 0000 ;; eof
jz EndLoop
cmp byte [cs:buffer_byte], 0x0A
jz EndLoop
cmp byte [cs:buffer_byte], 0x0D
jz EndLoop
;push dx
;push ax
;mov dl, [cs:buffer_byte]
;mov ah, 02
;int 0x21
;pop ax
;pop dx
mov bx, [cs:output_handle]
push dx
push cx
mov cx, 1
mov dx, buffer_byte
mov ah, 0x40
int 0x21
pop cx
pop dx
jmp ReadWriteLoop
EndLoop:
pop ds
;;
; Uzdarome failus
mov bx, [cs:input_handle]
call procFClose
mov bx, [cs:output_handle]
call procFClose
return:
macPopAll
iret
Nustatymas:
; Gauname sena 88h vektoriu
push cs
pop ds
mov ax, 3588h ; gauname sena pertraukimo vektoriu
int 21h
; Saugome sena vektoriu
mov [cs:Senas_I88], bx ; issaugome seno doroklio poslinki
mov [cs:Senas_I88 + 2], es ; issaugome seno doroklio segmenta
; Nustatome sena vektoriu
mov dx, Naujas_I88
mov ax, 2588h ; nustatome pertraukimo vektoriu
int 21h
macPutString "OK ...", crlf, '$'
;lea dx, [Nustatymas + 1] ; dx - kiek baitu
mov dx, Nustatymas + 1
int 27h ; Padarome rezidentu
%include 'yasmlib.asm'
section .bss