-
Notifications
You must be signed in to change notification settings - Fork 0
/
hamming.asm
248 lines (208 loc) · 3.92 KB
/
hamming.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
.386
.model flat, stdcall
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;includem biblioteci, si declaram ce functii vrem sa importam
includelib msvcrt.lib
extern exit: proc
extern fscanf: proc
extern printf: proc
extern fprintf: proc
extern scanf: proc
extern fopen: proc
extern fclose: proc
extern fseek: proc
include mylib.asm
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;declaram simbolul start ca public - de acolo incepe executia
public start
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;sectiunile programului, date, respectiv cod
.data
mode_read DB "r",0
mode_write DB "w",0
format DB "%s",0
file_name DB "fisier.in",0
fileout_name DB "rez.out",0
decimal DB "%d",0
sir DB 32 DUP(30h),0
sir_hamming DB 38 DUP(48),0
adresa_fisier_citire DD 0
adresa_fisier_scriere DD 0
message_correct DB "Correct!",0
message_incorrect DB "Error on bit %d",0
message_wrong DB "Incorect!",0
message_corrected_array DB "Correct: %s",0
options DB "Choose one option:",10,"1 - Generate Hamming Code",10,"2 - Check Hamming Code",10,0
val_option DD 0
wrongbit DD 0
newline DD 10
nr_adrese DD 1024
var_seek_cur dd 1
var2 dd 2
;aici declaram date
.code
reinit_ham proc
push EBP
mov EBP,ESP
mov ESI,[EBP+8]
mov al,30h
mov [ESI],al
add ESI,1
mov [ESI],al
add ESI,2
mov [ESI],al
add ESI,4
mov [ESI],al
add ESI,8
mov [ESI],al
add ESI,16
mov [ESI],al
mov ESP,EBP
pop EBP
ret 4
reinit_ham endp
start:
;aici se scrie codul
;deschidere_fisier_citire:
push offset options
push offset format
call printf
add ESP,8
push offset val_option
push offset decimal
call scanf
add ESP,8
mov ebx,val_option
cmp ebx,2
je checkoption
generateoption:
push offset mode_read
push offset file_name
call fopen
add ESP,8
mov adresa_fisier_citire,EAX
push offset mode_write
push offset fileout_name
call fopen
add ESP,8
mov adresa_fisier_scriere,EAX
mov ECX,nr_adrese
citire_sir:
push ECX
push offset sir
push offset format
push adresa_fisier_citire
call fscanf
add ESP,12
push offset sir_hamming
call reinit_ham
push offset sir_hamming
push offset sir
call generate_hamming
push offset sir_hamming
push offset format
call printf
add ESP,8
push offset newline
push offset format
call printf
add ESP,8
push offset sir_hamming
push offset format
push adresa_fisier_scriere
call fprintf
add ESP,12
push offset newline
push offset format
push adresa_fisier_scriere
call fprintf
add ESP,12
pop ECX
sub ECX,1
cmp ECX,0
jnz citire_sir
jmp finalizare
checkoption:
push offset mode_read
push offset fileout_name
call fopen
add ESP,8
mov adresa_fisier_scriere,eax
mov ECX,nr_adrese
citire_sir_hamming:
push ECX
push offset sir_hamming
push offset format
push adresa_fisier_scriere
call fscanf
add ESP,12
;push var_seek_cur
;push var2
;push adresa_fisier_scriere
;call fseek
;add ESP,12
;add var2,40
mov EDX,0
push offset sir_hamming
call check_hamming
mov wrongbit,edx
cmp wrongbit,0
je no_error
show_error:
push offset message_wrong
push offset format
call printf
add ESP,8
push offset newline
push offset format
call printf
add ESP,8
push wrongbit
push offset message_incorrect
call printf
add ESP,8
push offset newline
push offset format
call printf
add ESP,8
lea ESI,sir_hamming
add ESI,wrongbit
sub ESI,1
mov bl,30h
mov cl,31h
mov AL,[ESI]
cmp AL,30h
je process1
mov [ESI],bl
jmp skip1
process1:
mov [ESI],cl
skip1:
push offset sir_hamming
push offset message_corrected_array
call printf
add ESP,8
push offset newline
push offset format
call printf
add ESP,8
jmp dont_print_ok
no_error:
push offset message_correct
push offset format
call printf
add ESP,8
push offset newline
push offset format
call printf
add ESP,8
dont_print_ok:
pop ECX
sub ECX,1
cmp ECX,0
jnz citire_sir_hamming
finalizare:
;terminarea programului
push 0
call exit
end start