《字典汇编程序.doc》由会员分享,可在线阅读,更多相关《字典汇编程序.doc(153页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Four short words sum up what has lifted most successful individuals above the crowd: a little bit more.-author-date字典汇编程序dseg segment data实验报告实验目的 综合运用已学知识独立完成课程设计,熟练掌握汇编语言程序设计的基础知识。实验题目简易英英词典功能要求:1.单词及其英文解释的录入、修改和删除(1) 录入的新单词,把它插入到相应的位置(和一般词典一样);(2) 可修改单词英文解释;(3) 删除单词及其英文解释;2.查找:(1) 输入不完整的字符串,会依顺序列
2、出单词前缀和字符串相匹配的单词;如输入:en列出:enable, enabled, enact等(2) 查询某个单词英文解释(如enable: to provide with the means or opportunity; to make possible, practical, or easy),词库中不存在此单词,则提示找不到;(3) 查询某个单词的同义词(如accept: approve);(4) 查询某个单词的反义词(如win: lose);3.显示:界面美观实验内容一、数据文件结构说明1、每个词义(共4个)占64字节,近义词占64字节,反义词占64字节,均以$结束。2、单词索引表
3、置于文件尾,每个索引项中单词占22字节(包含结束符$),单词信息块位置信息占2字节。单词索引表以空格组成的串为结束标志。3、文件最末尾的6个字节,分别记录单词索引表中单词个数(包含空格组成的串),单词索引表距文件首的字节数(依次为高位字、低位字)。一、功能模块及主要宏、函数1、查询模块(1)、mycmps功能:字符串比较参数:mycmpstab0 字符串1偏移地址; mycmpstab2 字符串2偏移地址。返回:str1 str2 CF= 0, ZF= 0。(2)、halfsearch功能:字符串查找(折半)参数:halfsearchtab 0 字符串缓冲区偏移地址;halfsearchtab
4、 2 字符串个数; halfsearchtab 4 查询字符串偏移地址;halfsearchtab 6 字符串长度。返回:查找成功,CF=0,ax 返回匹配串的偏移地址。 查找不成功, CF=1,ax返回查询串插入时偏移地址。2、显示模块(1)、displayword功能:显示单词前缀和字符串相匹配的单词参数:displaywordtab0 字符串缓冲区偏移地址;displaywordtab2 显示字符串个数; displaywordtab4 字符串长度; displaywordtab6 亮行位置; displaywordtab8 返回光标位置; displaywordtab10 实际显示字符
5、串个数。返回:操作成功,displaywordtab10 返回实际显示字符串个数,光标位于displaywordtab8设置位置。(2)、readwordinfo功能:读取单词解释、近义词、反义词信息参数:readwordinfotab0 单词信息块位置;readwordinfotab2 存放信息块缓冲区偏移地址; readwordinfotab4 单词信息块大小。返回:操作成功,从文件中读取信息块于主存偏移地址为readwordinfotab2缓冲区中。(3)、showasentence功能:显示一条单词信息(4)、showwordinfo功能:显示单词信息参数:showwordinfota
6、b0 单词索引表中该单词的偏移地址; showwordinfotab2 单词信息缓冲区偏移地址; showwordinfotab4 单词信息块大小; showwordinfotab6 返回光标位置; showwordinfotab8 实际显示单词信息条数。返回:操作成功,显示单词信息,showwordinfotab8 返回实际显示单词信息条数,光标位于showwordinfotab6设置位置。3、编辑模块(1)、indexinsert功能:在单词索引表中插入一个单词参数:indexinserttab0 单词索引表偏移地址;indexinserttab2 单词索引表单词个数; indexinse
7、rttab4 单词大小;indexinserttab6 插入单词的偏移地址; indexinserttab8 插入位置偏移地址。返回:单词索引表中插入一个单词,完成索引表信息的维护。(2)、indexdelete功能:在单词索引表中删除一个单词参数:indexdeletetab0 单词索引表偏移地址;indexdeletetab2 单词索引表单词个数; indexdeletetab4 删除位置偏移地址。返回:单词索引表中删除一个单词,完成索引表信息的维护。(3)、inputnewinfo功能:接受新的单词信息哑元:bufad 存放新的单词信息的缓冲区偏移地址; maxindex 最大下标值,信
8、息中字符个数减结束符减1; charperline 输入时每行字符数; specialpoint 键入BackSpace需特殊处理的点; wndb 窗口属性; begincursor 接受字符起始光标位置。(4)、appdnewword功能:添加新的单词(5)、editnotfind功能:完成未找到匹配单词时的编辑(添加操作)参数:editnotfindtab 单词插入索引表位置偏移地址。(6)、delallwordinfo功能:删除一个单词。(7)、editfind功能:完成找到匹配单词时的编辑(修改、删除操作)参数:editfindtab单词插入索引表位置偏移地址。4、文件处理模块(1)、
9、createfile 功能:创建文件 参数:createfiletab0 ASCIZ串偏移地址; createfiletab2 文件属性; createfiletab4 出错信息偏移地址; createfiletab6 返回文件代号。 返回:操作成功,createfiletab6 返回文件代号,CF=0。 操作不成功, 输出提示信息,CF=1。(2)、openfile功能:打开文件 参数:openfiletab 0 ASCIZ串偏移地址;openfiletab 2 出错信息偏移地址。 返回:操作成功,handle返回文件代号,CF=0。 操作不成功, 输出提示信息,CF=1。(3)、movfp
10、功能:移动文件指针 参数:handle 文件代号; movfptab 0 移动方式码;movfptab 2 偏移字节数(高位);movfptab 4 偏移字节数(低位);movfptab 6 出错信息偏移地址。 返回:操作成功, CF=0。 操作不成功,输出提示信息,CF=1。(4)、wrfile功能:读/写文件 参数:handle 文件代号;wrfiletab 0 读/写;wrfiletab 2 数据缓冲区偏移地址;wrfiletab 4 读/写字节数;wrfiletab 6 出错信息偏移地址。 返回:操作成功, CF=0。 操作不成功,输出提示信息,CF=1。5、绘制界面模块(1)、dra
11、wwnd功能:绘制窗口哑元:attribute 窗口属性;wndleftr 左上角行号;wndleftc 左上角列号;wndrightr 右上角行号;wndrihgtc 右上角行号。(2)、setcursor功能:设置光标位置哑元:page 页号; row 行号; column 列号; addp 页号增量; addr 行号增量; addc 列号增量。(3)、interface功能:绘制界面(4)、operdeclare功能:显示操作说明二、程序流程图三、源程序dseg segment data indexelemsize equ 24 wordmaxsize equ 23 wordinfosi
12、ze equ 64 wordmeaningsize equ 384 Up equ 48h Down equ 50h Left equ 4Bh BackSpace equ 08h KeyEsc equ 1bh Dollar equ 24h Enter equ 0dh dictionary db Weeds Dictionary 1.0$ inpmsg db Input the word:$ indexmsg db Index:$ welcomemsg db Welcome to use Weeds Dictionary 1.0$ pathmsg db Please input the path
13、of words.dat$ escmsg db Esc: exit$ entermsg db Enter: edit$ bslmsg db BackSpace and Left: step back$ upmsg db Up: line up$ downmsg db Down: line down$ meaningmsg db Meaning:$ synonymsmsg db Synonyms:$ antonymmsg db Antonym:$ nofindmsg0 db NO FIND! _$ nofindmsg1 db PRESS ENTER TO EDIT THE WORD! _$ ed
14、itnotfindmsg db Append(A) $ appendmsg db Append:$ editfindmsg db Modify(M) Delete(D) $ modifymsg db Modify:$ deletemsg db Delete:$ optionmsg0 db Word(W) $ optionmsg1 db Meaning(M) Synonyms(S) $ optionmsg2 db Antonym(A) $ optretmsg db Return(R): $ operfinmsg db Operation has finished! *_*$ retmsg db
15、Enter R or r to return: $ nosynonymsmsg db no synonyms$ noantonymmsg db no antonym$ meaningnomsg db Meaning NO.(14): $ savechgmsg db Save the information? Y/N $ delmsmsg db Delete the information? Y/N $ delnotemsg db LOSE ALL WORDS INFORMATION: Y/N $ mdfywdmsg db !_! REALLY TO DO THAT: Y/N $ crefilm
16、sg db ERROR: createfile()$ opefilmsg db ERROR: openfile()$ movfpmsg db ERROR: movfp()$ wrfilemsg db ERROR: wrfile()$ clsfilmsg db ERROR: closefile()$ defaultpath db c:weeddic, 0 wndone1r db 0 wndone1c db 0 wndone2r db 24 wndone2c db 79 wndoneb db 96h barone1r db 1 barone1c db 0 barone2r db 1 barone2
17、c db 79 baroneb db 70h bartwo1r db 2 bartwo1c db 31 bartwo2r db 24 bartwo2c db 31 bartwob db 70h wndtwo1r db 4 wndtwo1c db 3 wndtwo2r db 5 wndtwo2c db 26 wndtwob db 0fch wndthree1r db 9 wndthree1c db 3 wndthree2r db 22 wndthree2c db 26 wndthreeb db 0f2h wndfour1r db 4 wndfour1c db 36 wndfour2r db 22
18、 wndfour2c db 75 wndfourb db 0fdh wndwel1r db 10 wndwel1c db 20 wndwel2r db 14 wndwel2c db 57 wndwelb db 0e0h wndeditb db 0f5h wndsaveb db 0edh wndeditnb db 0f6h mycmpstab dw 2 dup(?);str1ad str2ad halfsearchtab dw 4 dup(?);wordsad tablen searchwordad wordsize indexinserttab dw 5 dup(?);indexad inde
19、xlen wordsize inswordad insertad indexdeletetab dw 4 dup(?);indexad indexlen wordsize deletead displaywordtab dw 7 dup(?);wordarrad displaynum wordsize lightline retcursor realdispnum showwordinfotab dw 5 dup(?);wordad wordinfoad wordinfosize nonemptynum returncursor readwordinfotab dw ? ;wordplace
20、inputpath db 37, 0 pathname db 37 dup(?) handle dw ? ;share createfiletab dw 4 dup(?) ;ascizad fileattribute msgad rethandle openfiletab dw 2 dup(?) ;pathname msgad movfptab dw 4 dup(?) ;movfpway movfph movfpl msgad wrfiletab dw 4 dup(?) ;w/r, bufferad size msgad closefiletab dw ? ;msgad findflag db
21、 ? cpyflag db ? editnotfindtab dw ? ;insertplace editflag db 0 ;ifedit editfindtab dw ? ;deletead indexinfo dw 3 dup(?) searchword db 23 dup(Dollar) wordmeaning label byte wordm1 db 64 dup(?) wordm2 db 64 dup(?) wordm3 db 64 dup(?) wordm4 db 64 dup(?) similar db 64 dup(?) opposite db 64 dup(?) words
22、index db 10000 dup(?)dseg endssseg segment stack stack db 256 dup(0)sseg endscseg segment code assume ds:dseg, ss:sseg, cs:cseg pushregister macro r1, r2, r3, r4 push r1 push r2 push r3 push r4 endm popregister macro r1, r2, r3, r4 pop r1 pop r2 pop r3 pop r4 endm drawwnd macro attribute, wndleftr,
23、wndleftc, wndrightr, wndrihgtc pushregister ax, bx, cx, dx mov ax, 0600h mov bh, attribute mov ch, wndleftr mov cl, wndleftc mov dh, wndrightr mov dl, wndrihgtc int 10h popregister dx, cx, bx, ax endm setcursor macro page, row, column, addp, addr, addc push ax push bx push dx mov ah, 2 mov bh, page
24、add bh, addp mov dh, row add dh, addr mov dl, column add dl, addc int 10h pop dx pop bx pop ax endm printc macro char push ax push dx mov ah, 2 mov dl, char int 21h pop dx pop ax endm printstr macro strname push ax push dx mov ah, 9 mov dx, offset strname int 21h pop dx pop ax endm putstr macro stra
25、ddr push ax push dx mov ah, 9 mov dx, straddr int 21h pop dx pop ax endm interface macro drawwnd wndoneb, wndone1r, wndone1c, wndone2r, wndone2c drawwnd baroneb, barone1r, barone1c, barone2r, barone2c drawwnd bartwob, bartwo1r, bartwo1c, bartwo2r, bartwo2c drawwnd wndtwob, wndtwo1r, wndtwo1c, wndtwo
26、2r, wndtwo2c drawwnd wndthreeb, wndthree1r, wndthree1c, wndthree2r, wndthree2c drawwnd wndfourb, wndfour1r, wndfour1c, wndfour2r, wndfour2c setcursor 0, 0, 28, 0, 0, 0 printstr dictionary setcursor 0, 3, 3, 0, 0, 0 printstr inpmsg setcursor 0, 8, 3, 0, 0, 0 printstr indexmsg endm operdeclare macro s
27、etcursor 0, wndfour1r, wndfour1c, 0, 1, 3 printstr escmsg setcursor 0, wndfour1r, wndfour1c, 0, 2, 3 printstr entermsg setcursor 0, wndfour1r, wndfour1c, 0, 3, 3 printstr bslmsg setcursor 0, wndfour1r, wndfour1c, 0, 4, 3 printstr upmsg setcursor 0, wndfour1r, wndfour1c, 0, 5, 3 printstr downmsg endm
28、 firstuse macro drawwnd wndwelb, wndwel1r, wndwel1c, wndwel2r, wndwel2c setcursor 0, wndwel1r, wndwel1c, 0, 1, 1 printstr welcomemsg setcursor 0, wndwel1r, wndwel1c, 0, 2, 2 printstr pathmsg setcursor 0, wndwel1r, wndwel1c, 0, 3, 1 mov ah, 0ah mov dx, offset inputpath int 21h mov bh, 0 mov bl, input
29、path1 add bx, 2 mov inputpathbx, 0 mov createfiletab0, offset defaultpath mov createfiletab2, 02 mov createfiletab4, offset crefilmsg call createfile mov ax, createfiletab6 mov handle, ax mov wrfiletab0, 4000h mov wrfiletab2, offset inputpath1 mov wrfiletab4, bx mov wrfiletab6, offset crefilmsg call
30、 wrfile mov closefiletab0, offset clsfilmsg call closefile endm notfirstuse macro mov wrfiletab0, 3f00h mov wrfiletab2, offset inputpath1 mov wrfiletab4, 1 mov wrfiletab6, offset wrfilemsg call wrfile mov wrfiletab2, offset pathname mov ah, 0 mov al, inputpath1 mov wrfiletab4, ax call wrfile mov clo
31、sefiletab0, offset clsfilmsg call closefile sub wndwel2r, 2 drawwnd wndwelb, wndwel1r, wndwel1c, wndwel2r, wndwel2c setcursor 0, wndwel1r, wndwel1c, 0, 1, 1 printstr welcomemsg add wndwel2r, 2 mov ah, 1 or ch, 20h int 10h mov ax, 3000h mov cx, 0ffffh timedelay: timdly: loop timdly dec ax jnz timedel
32、ay mov ah, 1 mov ch, 0dh mov cl, ch int 10h endm main proc far mov ax, dseg mov ds, ax mov es, ax mov ax, 3 ;screeninitialize int 10h interface mov ax, 3d00h mov dx, offset defaultpath int 21h mov handle, ax jc firsttime notfirstuse jmp dicstart firsttime: firstuse dicstart: interface mov openfileta
33、b0, offset pathname ;open words.dat mov openfiletab2, offset opefilmsg call openfile jc firsttime operdeclare setcursor 0, wndtwo1r, wndtwo1c, 0, 0, 3 mov movfptab0, 4202h;read indexinformation:len add mov movfptab2, 0ffffh mov movfptab4, 0fffah mov movfptab6, offset movfpmsg call movfp jc toclosefi
34、le mov wrfiletab0, 3f00h mov wrfiletab2, offset indexinfo mov wrfiletab4, 6 mov wrfiletab6, offset wrfilemsg call wrfile jc toclosefile mov movfptab0, 4200h;wordsindex mov dx, indexinfo4 mov movfptab2, dx mov cx, indexinfo2 mov movfptab4, cx call movfp jc toclosefile mov ax, indexinfo0 mov dx, index
35、elemsize mul dx cmp dx, 0 jz readwordsindex setcursor 0, wndfour1r, wndfour1c, 0, 1, 3 putstr openfiletab0 jmp toclosefile readwordsindex: mov wrfiletab2, offset wordsindex mov wrfiletab4, ax call wrfile jc toclosefile redwdindfin: ;input search word mov halfsearchtab0, offset wordsindex mov halfsea
36、rchtab4, offset searchword mov halfsearchtab6, indexelemsize mov displaywordtab2, 10 mov displaywordtab4, wordmaxsize mov displaywordtab8, 405h ;not beyond 418h mov readwordinfotab2, offset wordm1 mov readwordinfotab4, wordmeaningsize mov showwordinfotab2, offset wordm1 mov showwordinfotab4, wordinf
37、osize mov cx, 0 mov si, 0 mov findflag, 2 getchar: mov ah, 0 int 16h cmp al, KeyEsc jz escape cmp al, Enter jnz notenter cmp byte ptr findflag, 2 jz notenter cmp byte ptr findflag, 1 jnz calleditnotfind mov di, 0 ;di is use to be a flag, if al is a char then di = 1 call editfind jmp dealwithchar calleditnotfind: mov di, 0 call editnotfind jmp dealwithchar notenter: cmp word ptr displaywordtab8, 418h ja notletter cmp al, Dollar jz notletter cmp al, 20h jb notletter cmp al, 7eh jbe isletter isletter: mov ah, 2 mov bh, 0 mov dx, displaywordtab8 int 10h mov ah, 2 mov dl, al int 21h mov
限制150内