功能要求:
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