Assembly 基于字典的压缩算法:汇编语言
基于字典的压缩算法: 基于字典的压缩算法: 1.分析文件并列出文本中的所有单词,而不考虑 大写和多个外观(构建组成 文本)。每个单词都分配了一个ASCII字符,构建字典也是如此。 2.在文本文件中,将用相应的(ASCII字符)替换单词 字典。它将保存新的磁盘文件和另一个包含字典的文件 问题是我的代码不起作用。当我打开de.exe文件时。出现消息“文件夹路径”,当我写入文件夹名称并按enter键时,它停止工作Assembly 基于字典的压缩算法:汇编语言,assembly,x86,Assembly,X86,基于字典的压缩算法: 基于字典的压缩算法: 1.分析文件并列出文本中的所有单词,而不考虑 大写和多个外观(构建组成 文本)。每个单词都分配了一个ASCII字符,构建字典也是如此。 2.在文本文件中,将用相应的(ASCII字符)替换单词 字典。它将保存新的磁盘文件和另一个包含字典的文件 问题是我的代码不起作用。当我打开de.exe文件时。出现消息“文件夹路径”,当我写入文件夹名称并按enter键时,它停止工作 .386 .model flat, stdcall ;;;;;;;;;;;;;;;;;;
.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
在两次fopen调用中,您都在同一寄存器EBX中保存EAX。那么第一次做有什么意义呢
;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
基本上,您正在读取输出文件。传递到
scanf
的缓冲区只能容纳8个字符和空终止符。你对这个项目有什么意见?可能它太长了,scanf
正在覆盖其他变量。text.txt是输入,wright?不,这取决于当你被要求输入文件路径时你写了什么:)但我猜用户3144770给出的答案指向了另一个更严重的问题。