功能要求:
1.单词及其英文解释的录入、修改和删除
(1 ) 录入新单词,把它插入到相应的位置(按词典顺序),其后跟英文解释、同义词、反义词;(此功能要求在文件中完成,其它功能可以将单词放在数据段中)
(2 ) 可修改单词英文解释;
(3 ) 删除单词及其英文解释;
2.查找:
- 输入不完整的字符串,会依顺序列出单词前缀和字符串相匹配的单词;
如输入:en
列出:enable, enabled, enact等
- 查询某个单词英文解释(如enable: to provide with the means or opportunity; to make possible, practical, or easy),词库中不存在此单词,则提示找不到;
- 查询某个单词的同义词(如accept: approve);
- 查询某个单词的反义词(如win: lose);
以上结果均需显示
编译环境:VScode, msdos player MASM-v5.00
字符编码方式:UTF-8
使用说明:
1. 进入界面后首先是输入单词,只允许输入小写字母,按下回车选中自动选中匹配的第一个单词,在此阶段按 esc 键退出程序
2. 按下回车选中单词,如果没有匹配的单词自动清空重新输入需要查询的单词
3. 查询、修改命令:
:s 同义词 :o 反义词 :e 解释 :d 删除单词 :q 退出编辑/当前单词,重新搜索 :i 编辑解释 :w 保存修改(上一次操作为编辑解释有效)
4. 编辑解释,输入 :q 后光标自动跳到解释框,输入新的解释,遇到 : 结束,输入下一个命令
5. 输入 :q 退出查询后返回到输入单词搜索阶段
效果展示:
搜索匹配:
按下enter 选中匹配的第一个单词
查询解释:
查询反义词
查询近义词
修改解释
修改后的解释
修改解释未保存
修改后直接查询近义词,不保存解释
还是原来的解释
absent删除后重新查询后,没有absent
词库未录入 k 开头的单词显示找不到
代码
; multi-segment executable file template.
; 回车 确定 :s 同义词 :o 反义词 :e 解释 :d 删除单词 :q 退出编辑/当前单词,重新搜索 :i 编辑(只对解释有效) :w 保存修改 键 esc 退出程序
; 示例:white:expl[回车] 查看解释 :i[回车] 编辑解释 :s[回车] 保存解释WordMaxLen equ 30 ; 单词最大长度
MaxCntWord equ 200 ; 最多存储的单词数
WordNum equ 38 ; 输入的单词数
ExplLen equ 200 ; 单词解释最大长度readline macro adrlocal lop, checklea dx, adrdec dxlop: mov bx, readptrmov cx, 1 ;; 逐个字节读入inc dxmov ah, 3fhint 21hmov bx, dxmov al, ds:[bx]cmp al, 0dh ;; 判断是否是回车jnz lopmov byte ptr ds:[bx], '$' ;; 加上结束符 '$'mov bx, readptrmov cx, 0mov dx, 1mov al, 01hmov ah, 42hint 21h ;; 读指针向后移一位,跳过换行endmscroll macro n, ulr, ulc, lrr, lrc, att, modeifidni <u>, <mode>mov ah, 6elsemov ah, 7endifmov al, n ;n = 上卷行数;n = 0时,整个窗口空白mov ch, ulr ;左上角行号mov cl, ulc ;左上角列号mov dh, lrr ;右下角行号mov dl, lrc ;右下角列号mov bh, att ;卷入行属性int 10H
endmcurse macro cury,curxmov ah, 2 ;置光标位置mov dh, cury ;行号mov dl, curx ;列号mov bh, 0 ;当前页int 10H
endmdispscreen macro ;; 需预先设置好 ds, si, cx 和光标local dislop, disretdislop: cldlodsbcmp al, '$' ;; 遇到 $ 结束jz disretmov ah, 0ehmov bh, 0int 10hloop dislopdisret:
endmworddata strucwname db WordMaxLen+1 dup('$') ; 单词explain db ExplLen dup('$') ; 解释syn db WordMaxLen dup('$') ; 同义词opp db WordMaxLen dup('$') ; 反义词
worddata endsdata segmentcntword dw 0 ; 保存单词的个数readptr dw ?words worddata MaxCntWord dup(<>) ; 单词存储区filename db 'D:\assembly_language_program\curriculum_design\finalword.txt', 0 ; 单词文件路径err db 'can not open file$'adr dw ?inputbuf db WordMaxLen+1 dup('$') ; 单词搜索框,显示当前单词flag db 0 ; 是否修改解释
data endsshowdata segmentseletw dw ? ; 匹配的单词数cmdbuf db 10 dup('$') ; 模式选择框showbuf db ExplLen dup('$') ; 输入解释curp db 0 ; 光标位置noword db 'there is no such word in the data base$'shwords dw MaxCntWord dup(?) ; 保存匹配的单词
showdata endsinputinit macroscroll 0, 0, 0, 0, 79, 0e0h, u ;; 单词输入框curse 0, 0
endmexplinit macroscroll 0, 1, 0, 17, 79, 0f1h, u ;; 解释显示框curse 1, 0
endmcmdinit macroscroll 0, 18, 0, 18, 79, 0b0h, u ; 命令输入框curse 18,0
endmstack segment stackdw 1024 dup(0)
stack endscode segmentassume cs:code, ds:data, es:showdata, ss:stackstart: ; set segment registers:mov ax, datamov ds, axmov ax, showdatamov es, axcall init ; 读入单词inputinitexplinitcmdinitcurse 0, 0get1: lea ax, inputbufmov si, axmov cx, 30 ; 置一行字符数get2: mov ah, 0 ; 等待输入int 16hcmp al, 1bh ; 是否为 esc 键?jz exit ; 是,退出cmp al, 'a' ; 输入单词,只允许输入字母jc nextincmp al, 'z'ja nextindispin: mov [si], alinc simov ah, 0eh ; 显示输入的字符int 10Hpush cxmov ah, 03h ; 获取光标位置mov bh, 0int 10hpush dx ; 保存光标位置call matchpop dx ; 恢复光标位置mov bh, 0mov ah, 2int 10hpop cxloop get2nextin: cmp al, 0dh ; 按下回车选中第一个单词,进入单词查询、修改jnz nextin1call opwordinputinit ; 清空输入框输入下一个单词loop get1nextin1: inc cx ; 输入的不是字母或回车,重新输入这一位loop get2inputinitcall inputbufclearjmp get1 ; 超过 30 个字母重新输入exit: scroll 0,0,0,24,79,7 ; 清屏mov ax, 4c00h ; exit to operating system.int 21hinit proc ; 初始化lea dx, filenamemov ah, 3dhmov al, 00hmov cx, 00hint 21h ; 打开文件cmp cx, 0jnz notfile ; 打开失败mov readptr, ax ; 保存文件标识lea dx, wordsmov cx, WordNumlop1: mov adr, dxcall readwordpush dxcall adjustadd dx, type worddatainc cntword ; 计数loop lop1jmp returnnotfile: mov ax, cxlea dx, errmov ah, 09hint 21hreturn: mov ah, 3ehmov bx, readptrint 21hret
init endpreadword proc ; 读入一个单词的内容,通过 adr 传递参数irp regad, <ax, bx, cx, dx, si, di>push regad
endmmov ax, adrmov si, axreadline [si].wnamereadline [si].explainreadline [si].synreadline [si].oppirp regad, <di, si, dx, cx, bx, ax>pop regad
endmret
readword endpcmpstr proc ; 比较两个字符串的字典序, 通过堆栈传递参数,cl 返回结果irp regad, <ax, bx, dx, si, di, bp, es>push regad
endmmov bp, spadd bp, 16mov di, [bp]add bp, 2mov si, [bp]mov ax, datamov es, axmov cx, WordMaxLencldrepe cmpsbmov cl, [si - 1] ; 计算放回值,通过两个不同的位置相减得到sub cl, es:[di - 1]irp regad, <es, bp, di, si, dx, bx, ax>pop regad
endmret 4
cmpstr endpexchangeword proc ; 交换两个单词的位置,通过堆栈传递两个单词的地址irp regad, <ax, bx, cx, dx, si, di, bp, es>push regad
endmmov bp, spadd bp, 18mov ax, [bp]mov si, axadd bp, 2mov ax, [bp]mov di, axmov ax, datamov es, axmov cx, type worddataxchglop: mov al, [si] ; 按字节交换单词xchg al, es:[di]xchg al, [si]inc siinc diloop xchglopirp regad, <es, bp, di, si, dx, cx, bx, ax>pop regad
endmret 4
exchangeword endpadjust proc ; 调整单词的位置,通过堆栈传递单词地址irp regad, <ax, bx, cx, dx, si, di, bp, es>push regad
endmmov bp, spadd bp, 18mov dx, [bp]mov ax, dxsub ax, type worddataadjlop: cmp dx, offset wordsjz adjret ; 如果在第一个位置返回push dxpush axcall cmpstr ; 和上一个字符串比较test cl, 80h ; 判断比较结果,判断 cl 是否是负数jz adjret ; 如果大于 0 说明到达对应位置push dxpush axcall exchangeword ; 向前调整sub dx, type worddatasub ax, type worddatajmp adjlopadjret: irp regad, <es, bp, di, si, dx, cx, bx, ax>pop regad
endmret 2
adjust endpexpldisp proc ; 通过堆栈传递需要输出的内容mov bp, spadd bp, 2push simov ax, [bp]mov si, axexplinitmov cx, 80 ; 一行 80 个字符dispscreencmp al, '$'jz showexplcurse 2, 0mov cx, 80dispscreenshowexpl: mov dx, sipop siret 2
expldisp endpcursep proccurse 2, 0ret
cursep endpexplainintip procexplinitret
explainintip endpcmd1 proccmp al, 'e'jnz cmd1retlea ax, [si].explainpush axcall expldispmov al, 0mov flag, alcmd1ret: ret
cmd1 endpcmd2 proccmp al, 's'jnz cmd2retlea ax, [si].synpush axcall expldispmov al, 0mov flag, alcmd2ret: ret
cmd2 endpcmd3 proccmp al, 'o'jnz cmd3retlea ax, [si].opppush axcall expldispmov al, 0mov flag, alcmd3ret: ret
cmd3 endpcmd4 procirp regad, <ax, bx, cx, dx, si, di, es, ds>push regad
endmcmp al, 'w'jnz cmd4retmov al, 1 ; 上一步是修改解释则写入cmp flag, aljnz cmd4retmov cx, 100lea ax, [si].explainmov di, axlea ax, showbufmov si, axmov ax, esmov bx, dsxchg ax, bxmov ds, bxmov es, axcldrep movsbmov al, 0mov flag, alcmd4ret: irp regad, <ds, es, di, si, dx, cx, bx, ax>pop regad
endmret
cmd4 endpcmd5 procirp regad, <ax, bx, cx, dx, si, di, es, ds>push regad
endmcmp al, 'd'jnz cmd5retmov ax, cntworddec axmov dx, type worddatamul dxadd ax, offset wordsmov bx, simov dx, bxadd dx, type worddataswap: cmp bx, axjz cmd5retpush dxpush bxcall exchangewordadd bx, type worddataadd dx, type worddatajmp swapcmd5ret: dec cntwordirp regad, <ds, es, di, si, dx, cx, bx, ax>pop regad
endmret
cmd5 endpinputinitp procinputinitdispscreenret
inputinitp endpcmdinitp proccmdinitret
cmdinitp endpinputbufclear procirp regad, <ax, bx, cx, dx, si, di, es, ds>push regad
endmmov cx, WordMaxLen+1 ; 清空输入框的内容mov ax, datamov es, axlea ax, inputbufmov di, axmov al, '$'cldrep stosbirp regad, <ds, es, di, si, dx, cx, bx, ax>pop regad
endmret
inputbufclear endpopword proc ; 对选中的单词进行操作irp regad, <ax, bx, cx, dx, si, di, es>push regad
endmmov ax, es:[seletw]cmp ax, 0jz opretmov ax, es:[shwords]mov si, axpush sicall inputinitppop sicall explainintipwaitinput: mov ah, 0 ; 等待输入int 16hcmp al, ':'inputcmd: push axjnz waitinputcall cmdinitppop axmov ah, 0ehint 10hmov ah, 0 ; 等待输入int 16hmov ah, 0ehint 10hcmp al, 'q' ; 退出当前单词的查询jz opretcall cmd1call cmd2call cmd3call cmd4call cmd5cmp al, 'd' ; 已经把当前单词删除直接退出jz opretcmp al, 'i'jnz waitinputmov al, 1 ; 设置为 1 表示修改mov flag, almov cx, 100mov al, '$' ; 清空输入缓存lea dx, showbufmov di, dxrep stosblea dx, showbufmov di, dxcall explainintipmov cx, 80 ; 允许输入单词的长度为 80inputexp: mov ah, 0 ; 等待输入int 16hcmp al, ':' ; 遇到 : 表示输入解释结束,进入下一个命令jz inputcmdmov bh, 0mov ah, 0ehint 10hstosbloop inputexpjmp waitinputopret: call cmdinitpcall inputbufclear ; 清空输入缓存call explainintip ; 清屏irp regad, <es, di, si, dx, cx, bx, ax>pop regad
endmret
opword endpmatch proc ; 匹配单词irp regad, <ax, bx, cx, dx, si, di, es, ds, bp>push regad
endmmov ax, 0mov es:[seletw], axscroll 0, 1, 0, 17, 79, 0f0h, u ; 清屏curse 1,0mov es:[curp], 1 ; 保存光标位置mov cx, ds:[cntword]lea ax, wordsmov si, axlea ax, inputbufmov di, axmov ax, datamov es, axlop2: push cxpush dipush simov cx, 30 ; 开始匹配repe cmpsbmov al, '$' ; 遇到 $ 表达匹配成功cmp al, es:[di - 1]jnz notmatchpush esmov ax, showdatamov es, axpop bppop sipush sipush bpmov bx, es:[seletw]shl bx, 1add bx, offset shwords ; 计算保存新的匹配单词的位置mov ax, simov es:[bx], ax ; 保存单词的地址inc es:[seletw] ; 计数pop esmov cx, 30pop si ; 取出当前单词的首地址push sidispscreen ; 输出匹配的单词push esmov ax, showdata ; 光标下移mov es, axinc es:[curp] ; 光标下移curse es:[curp], 0pop esnotmatch: pop sipop dipop cxmov ax, siadd ax, type worddata ; 匹配下一个单词mov si, axloop lop2push esmov ax, showdatamov es,axmov ax, 0cmp es:[seletw], axpop esjnz matchretlea ax, noword ; 没有匹配到任何单词输出错误mov si, axmov ax, showdatamov ds, axmov cx, 80dispscreenmatchret: irp regad, <bp, ds, es, di, si, dx, cx, bx, ax>pop regad
endmret
match endpcode endsend start ; set entry point and stop the assembler.
代码有些 bug 使用时可以自己测试修改。
单词文件
absent
not present, lacking, or not attending
missing
present
ambitious
having a strong desire for success, power, or wealth
aspiring
content
blind
lack of sight or insight
sightless
seeing
bound
obliged by law, morality, or contract
limited
unlimited
bourgeois
relating to the middle class or its values and attitudes
middle-class
proletarian
cavity
an empty space within a solid object or among layers
hollow
solid
conservative
inclined to preserve existing conditions, ideas, or institutions
traditionalist
progressive
decisive
resolute; determined to act in a particular way
firm
indecisive
divine
relating to deity or the supernatural; godlike
heavenly
earthly
empirical
based on experiment and observation alone, without using intuitions or theories
experimental
theoretical
fantastic
imaginatively appealing or amusing
bizarre
realistic
fitting
appropriate and suitable for a particular purpose or occasion
appropriate
inappropriate
gracious
characterized by kindness, courtesy, and generosity
kind
rude
grassy
covered with grass or resembling grass
verdant
barren
hoarse
rough or low in tone; not clear and ringing
gravelly
melodious
hostile
showing active dislike or enmity
unfriendly
friendly
icy
extremely cold or covered with ice
frosty
warm
inclusive
including everything within a specified category or boundary
comprehensive
exclusive
linear
of or relating to a line or lines
straight
nonlinear
luminous
emitting or reflecting light; glowing
bright
dark
main
most important or prominent; chief
principal
secondary
microscopic
too small to be seen by the unaided eye; requiring a microscope for examination
minute
macroscopic
neighbouring (or neighboring)
located close to someone or something else; adjacent
adjacent
distant
novel
new and different from what has been done or known before; original
original
familiar
optical
relating to the sense of sight or to light
visual
tactile
practicable
capable of being accomplished or put into practice; feasible
feasible
impractical
qualitative
concerned with qualities rather than quantities or measurements
nonquantitative
quantitative
regenerative
tending to reform or restore itself after injury or loss
restorative
destructive
rigorous
very strict and exacting; stern or severe
strict
lenient
senseless
lacking common sense or judgment; wildly foolish
foolish
sensible
smart
intelligent and well-informed; clever and able to make good judgments
intelligent
dumb
thorough
carried out carefully and completely; leaving no room for error or omission
complete
superficial
tiresome
making you feel tired or bored; annoying or difficult to deal with
annoying
pleasant
uncertain
not known or established; doubtful or not definite
unclear
certain
versatile
capable of doing many different things well; adaptable and flexible
adaptable
one-dimensional
vulgar
lacking in refinement or good taste; crude or offensive in language or behavior
rude
elegant
workpiece
an object that is being worked on or that is to be worked on; a piece of workmanship
project
tool
white
of the color of pure snow; having no color or no pigment; lacking normal color as a result of genetic defect or disease
pale
blac