словарю алгоритм сжатия:алгоритм сжатия на основе словаря: на ассемблере
словаря на основе алгоритма сжатия: 1. проанализировать файл и сделать список всех слов в тексте, не принимая во внимание верхний регистр и многократное появление (строит набор слов, которые составляют текст ). Каждому слову присваивается символ ASCII, поэтому создается словарь. 2. В текстовом файле замените слова своим корреспондентом (символ ASCII) словаря . Он сохранит новый файл диска и другой файл, содержащий словарь.
Проблема в том, что мой код не работает. Когда я открываю файл .exe. появляется сообщение «путь к папке», и когда я пишу имя папки и нажимаю Enter, он перестает работать.
.386
.model flat, stdcall
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;include libraries, and declare what functions we want to import
includelib msvcrt.lib
extern printf: proc
extern fscanf: proc
extern fopen: proc
extern fprintf: proc
extern fclose: proc
extern printf: proc
extern scanf: proc
extern exit: proc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
public start
;declare the start symbol as public - from there the execution begins
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;sections of the program, data or code
.data
mesaj1 db "path to the folder:", 0
format db "%s", 0
format_cit db "%s", 0
format_dic db "%d", 0
filename db "text.txt", 0
mode_r db "r", 0
wfilename db "text2.txt", 0
mode_w db "w", 0
dfilename db "dic.txt", 0
n db 10 dup(0)
DICTIONAR struct
cuv db 10 dup(0)
var dd 0
DICTIONAR ends
var DICTIONAR 10 dup({}) ;Initialize an array of struct DICTIONAR where it will save vocabulary
nr db 0
rez db 10 dup(0)
index db 0
virgula db ",", 0
.code
start:
;enter the path to the file
push offset mesaj1
call printf
add esp, 4
push offset filename
push offset format
call scanf
add esp, 8
;call fopen
push offset mode_r
push offset filename
call fopen
add esp, 8
mov ebx, eax ;salvam pointer-ul la fisier
;call fopen
push offset mode_w
push offset wfilename
call fopen
add esp,8
mov ebx, eax
;-
mov eax, esi; move the pointer on the reading file
lea edi, var[0].cuv
;put on the stack parameters for fread
readig_loop:
push offset n ;
push offset format_cit ;
push ebx ;stream
call fscanf
;-
mov edx,edi
;check if it has reached the end of the file
add eax,1
test eax, eax
jz inchidere_fisier
xor eax, eax ;facem eax sa fie 0
;-
;check if the vord exists in the dictionary
xor ecx,ecx ;curatam ecx
mov cl,nr ;put in cl the number of words from the dictionary
add cl,1 ;start count from 1
mov edi,edx
lea edx,var[0].cuv
add:
lea esi,n
dec edx
xor ebp,ebp
dec ebp
compare:
inc edx
inc ebp
lodsb
cmp [edx],al
jne different
cmp al,0
je egal
jne compare
different:
sub edx,ebp
add edx,12
loop add
mov edx,edi
lea esi,n
xor ebp,ebp
copy:
inc ebp
mov al,[esi]
cmp al,0
je done
mov[edx],al
inc esi
inc edx
jmp copy
done:
sub edx,ebp
inc edx
add [nr],1
add edx,10
mov cl,nr
add cl,48
mov [edx],cl
add edx,2
mov edi,edx
lea eax,rez
add al,index
mov [eax],cl
add [index],1
jmp bucla_citire
eqals:
sub edx,ebp
mov ebp,edx
add edx,10
lea eax,rez
add al,index
mov cl,[edx]
mov [eax],cl
add [index],1
mov edi,edx
jmp reading_loop
close_the_folder:
;call fclose
push ebx ;stream
call fclose
push offset mode_w
push offset wfilename
call fopen
write_fis:
push offset rez
push offset format
push eax
call fprintf
push offset rez
push offset format
call printf
;write in the dictionery file
push offset mode_w
push offset dfilename
call fopen
mov esp,eax
xor ebx,ebx
mov bl,nr
lea ebp,var[0].cuv
write_dic:
push ebp
push offset format
push esp
call fprintf
add ebp,10
xor ecx,ecx
mov cl,[esi]
push cx
push offset format_dic
push esp
call fprintf
add ebp,2
push offset virgula
push offset format
push esp
call fprintf
dec bl
cmp bl,0
jne write_dic
;end
push 0
call exit
end start
Буфер, который вы передаете 'scanf', может содержать только 8 символов и нулевой терминатор. Какой вклад вы даете программе? Возможно, он слишком длинный, и 'scanf' перезаписывает другие переменные. – Diego
text.txt - это вход, wright? –
ну, нет, это зависит от того, что вы пишете, когда вас просят указать путь к входному файлу :) Но я думаю, что ответ, заданный _user3144770_, указывает на другую проблему, которая является более серьезной. – Diego