功能要求:
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 adr
local lop, check
lea dx, adr
dec dx
lop:
mov bx, readptr
mov cx, 1 ;; 逐个字节读入
inc dx
mov ah, 3fh
int 21h
mov bx, dx
mov al, ds:[bx]
cmp al, 0dh ;; 判断是否是回车
jnz lop
mov byte ptr ds:[bx], '$' ;; 加上结束符 '$'
mov bx, readptr
mov cx, 0
mov dx, 1
mov al, 01h
mov ah, 42h
int 21h ;; 读指针向后移一位,跳过换行
endm
scroll macro n, ulr, ulc, lrr, lrc, att, mode
ifidni <u>, <mode>
mov ah, 6
else
mov ah, 7
endif
mov al, n ;n = 上卷行数;n = 0时,整个窗口空白
mov ch, ulr ;左上角行号
mov cl, ulc ;左上角列号
mov dh, lrr ;右下角行号
mov dl, lrc ;右下角列号
mov bh, att ;卷入行属性
int 10H
endm
curse macro cury,curx
mov ah, 2 ;置光标位置
mov dh, cury ;行号
mov dl, curx ;列号
mov bh, 0 ;当前页
int 10H
endm
dispscreen macro ;; 需预先设置好 ds, si, cx 和光标
local dislop, disret
dislop:
cld
lodsb
cmp al, '$' ;; 遇到 $ 结束
jz disret
mov ah, 0eh
mov bh, 0
int 10h
loop dislop
disret:
endm
worddata struc
wname db WordMaxLen+1 dup('$') ; 单词
explain db ExplLen dup('$') ; 解释
syn db WordMaxLen dup('$') ; 同义词
opp db WordMaxLen dup('$') ; 反义词
worddata ends
data segment
cntword 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 ends
showdata segment
seletw 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 ends
inputinit macro
scroll 0, 0, 0, 0, 79, 0e0h, u ;; 单词输入框
curse 0, 0
endm
explinit macro
scroll 0, 1, 0, 17, 79, 0f1h, u ;; 解释显示框
curse 1, 0
endm
cmdinit macro
scroll 0, 18, 0, 18, 79, 0b0h, u ; 命令输入框
curse 18,0
endm
stack segment stack
dw 1024 dup(0)
stack ends
code segment
assume cs:code, ds:data, es:showdata, ss:stack
start:
; set segment registers:
mov ax, data
mov ds, ax
mov ax, showdata
mov es, ax
call init ; 读入单词
inputinit
explinit
cmdinit
curse 0, 0
get1:
lea ax, inputbuf
mov si, ax
mov cx, 30 ; 置一行字符数
get2: mov ah, 0 ; 等待输入
int 16h
cmp al, 1bh ; 是否为 esc 键?
jz exit ; 是,退出
cmp al, 'a' ; 输入单词,只允许输入字母
jc nextin
cmp al, 'z'
ja nextin
dispin:
mov [si], al
inc si
mov ah, 0eh ; 显示输入的字符
int 10H
push cx
mov ah, 03h ; 获取光标位置
mov bh, 0
int 10h
push dx ; 保存光标位置
call match
pop dx ; 恢复光标位置
mov bh, 0
mov ah, 2
int 10h
pop cx
loop get2
nextin:
cmp al, 0dh ; 按下回车选中第一个单词,进入单词查询、修改
jnz nextin1
call opword
inputinit ; 清空输入框输入下一个单词
loop get1
nextin1:
inc cx ; 输入的不是字母或回车,重新输入这一位
loop get2
inputinit
call inputbufclear
jmp get1 ; 超过 30 个字母重新输入
exit:
scroll 0,0,0,24,79,7 ; 清屏
mov ax, 4c00h ; exit to operating system.
int 21h
init proc ; 初始化
lea dx, filename
mov ah, 3dh
mov al, 00h
mov cx, 00h
int 21h ; 打开文件
cmp cx, 0
jnz notfile ; 打开失败
mov readptr, ax ; 保存文件标识
lea dx, words
mov cx, WordNum
lop1:
mov adr, dx
call readword
push dx
call adjust
add dx, type worddata
inc cntword ; 计数
loop lop1
jmp return
notfile:
mov ax, cx
lea dx, err
mov ah, 09h
int 21h
return:
mov ah, 3eh
mov bx, readptr
int 21h
ret
init endp
readword proc ; 读入一个单词的内容,通过 adr 传递参数
irp regad, <ax, bx, cx, dx, si, di>
push regad
endm
mov ax, adr
mov si, ax
readline [si].wname
readline [si].explain
readline [si].syn
readline [si].opp
irp regad, <di, si, dx, cx, bx, ax>
pop regad
endm
ret
readword endp
cmpstr proc ; 比较两个字符串的字典序, 通过堆栈传递参数,cl 返回结果
irp regad, <ax, bx, dx, si, di, bp, es>
push regad
endm
mov bp, sp
add bp, 16
mov di, [bp]
add bp, 2
mov si, [bp]
mov ax, data
mov es, ax
mov cx, WordMaxLen
cld
repe cmpsb
mov cl, [si - 1] ; 计算放回值,通过两个不同的位置相减得到
sub cl, es:[di - 1]
irp regad, <es, bp, di, si, dx, bx, ax>
pop regad
endm
ret 4
cmpstr endp
exchangeword proc ; 交换两个单词的位置,通过堆栈传递两个单词的地址
irp regad, <ax, bx, cx, dx, si, di, bp, es>
push regad
endm
mov bp, sp
add bp, 18
mov ax, [bp]
mov si, ax
add bp, 2
mov ax, [bp]
mov di, ax
mov ax, data
mov es, ax
mov cx, type worddata
xchglop:
mov al, [si] ; 按字节交换单词
xchg al, es:[di]
xchg al, [si]
inc si
inc di
loop xchglop
irp regad, <es, bp, di, si, dx, cx, bx, ax>
pop regad
endm
ret 4
exchangeword endp
adjust proc ; 调整单词的位置,通过堆栈传递单词地址
irp regad, <ax, bx, cx, dx, si, di, bp, es>
push regad
endm
mov bp, sp
add bp, 18
mov dx, [bp]
mov ax, dx
sub ax, type worddata
adjlop:
cmp dx, offset words
jz adjret ; 如果在第一个位置返回
push dx
push ax
call cmpstr ; 和上一个字符串比较
test cl, 80h ; 判断比较结果,判断 cl 是否是负数
jz adjret ; 如果大于 0 说明到达对应位置
push dx
push ax
call exchangeword ; 向前调整
sub dx, type worddata
sub ax, type worddata
jmp adjlop
adjret:
irp regad, <es, bp, di, si, dx, cx, bx, ax>
pop regad
endm
ret 2
adjust endp
expldisp proc ; 通过堆栈传递需要输出的内容
mov bp, sp
add bp, 2
push si
mov ax, [bp]
mov si, ax
explinit
mov cx, 80 ; 一行 80 个字符
dispscreen
cmp al, '$'
jz showexpl
curse 2, 0
mov cx, 80
dispscreen
showexpl: mov dx, si
pop si
ret 2
expldisp endp
cursep proc
curse 2, 0
ret
cursep endp
explainintip proc
explinit
ret
explainintip endp
cmd1 proc
cmp al, 'e'
jnz cmd1ret
lea ax, [si].explain
push ax
call expldisp
mov al, 0
mov flag, al
cmd1ret:
ret
cmd1 endp
cmd2 proc
cmp al, 's'
jnz cmd2ret
lea ax, [si].syn
push ax
call expldisp
mov al, 0
mov flag, al
cmd2ret:
ret
cmd2 endp
cmd3 proc
cmp al, 'o'
jnz cmd3ret
lea ax, [si].opp
push ax
call expldisp
mov al, 0
mov flag, al
cmd3ret:
ret
cmd3 endp
cmd4 proc
irp regad, <ax, bx, cx, dx, si, di, es, ds>
push regad
endm
cmp al, 'w'
jnz cmd4ret
mov al, 1 ; 上一步是修改解释则写入
cmp flag, al
jnz cmd4ret
mov cx, 100
lea ax, [si].explain
mov di, ax
lea ax, showbuf
mov si, ax
mov ax, es
mov bx, ds
xchg ax, bx
mov ds, bx
mov es, ax
cld
rep movsb
mov al, 0
mov flag, al
cmd4ret:
irp regad, <ds, es, di, si, dx, cx, bx, ax>
pop regad
endm
ret
cmd4 endp
cmd5 proc
irp regad, <ax, bx, cx, dx, si, di, es, ds>
push regad
endm
cmp al, 'd'
jnz cmd5ret
mov ax, cntword
dec ax
mov dx, type worddata
mul dx
add ax, offset words
mov bx, si
mov dx, bx
add dx, type worddata
swap:
cmp bx, ax
jz cmd5ret
push dx
push bx
call exchangeword
add bx, type worddata
add dx, type worddata
jmp swap
cmd5ret:
dec cntword
irp regad, <ds, es, di, si, dx, cx, bx, ax>
pop regad
endm
ret
cmd5 endp
inputinitp proc
inputinit
dispscreen
ret
inputinitp endp
cmdinitp proc
cmdinit
ret
cmdinitp endp
inputbufclear proc
irp regad, <ax, bx, cx, dx, si, di, es, ds>
push regad
endm
mov cx, WordMaxLen+1 ; 清空输入框的内容
mov ax, data
mov es, ax
lea ax, inputbuf
mov di, ax
mov al, '$'
cld
rep stosb
irp regad, <ds, es, di, si, dx, cx, bx, ax>
pop regad
endm
ret
inputbufclear endp
opword proc ; 对选中的单词进行操作
irp regad, <ax, bx, cx, dx, si, di, es>
push regad
endm
mov ax, es:[seletw]
cmp ax, 0
jz opret
mov ax, es:[shwords]
mov si, ax
push si
call inputinitp
pop si
call explainintip
waitinput:
mov ah, 0 ; 等待输入
int 16h
cmp al, ':'
inputcmd:
push ax
jnz waitinput
call cmdinitp
pop ax
mov ah, 0eh
int 10h
mov ah, 0 ; 等待输入
int 16h
mov ah, 0eh
int 10h
cmp al, 'q' ; 退出当前单词的查询
jz opret
call cmd1
call cmd2
call cmd3
call cmd4
call cmd5
cmp al, 'd' ; 已经把当前单词删除直接退出
jz opret
cmp al, 'i'
jnz waitinput
mov al, 1 ; 设置为 1 表示修改
mov flag, al
mov cx, 100
mov al, '$' ; 清空输入缓存
lea dx, showbuf
mov di, dx
rep stosb
lea dx, showbuf
mov di, dx
call explainintip
mov cx, 80 ; 允许输入单词的长度为 80
inputexp:
mov ah, 0 ; 等待输入
int 16h
cmp al, ':' ; 遇到 : 表示输入解释结束,进入下一个命令
jz inputcmd
mov bh, 0
mov ah, 0eh
int 10h
stosb
loop inputexp
jmp waitinput
opret:
call cmdinitp
call inputbufclear ; 清空输入缓存
call explainintip ; 清屏
irp regad, <es, di, si, dx, cx, bx, ax>
pop regad
endm
ret
opword endp
match proc ; 匹配单词
irp regad, <ax, bx, cx, dx, si, di, es, ds, bp>
push regad
endm
mov ax, 0
mov es:[seletw], ax
scroll 0, 1, 0, 17, 79, 0f0h, u ; 清屏
curse 1,0
mov es:[curp], 1 ; 保存光标位置
mov cx, ds:[cntword]
lea ax, words
mov si, ax
lea ax, inputbuf
mov di, ax
mov ax, data
mov es, ax
lop2:
push cx
push di
push si
mov cx, 30 ; 开始匹配
repe cmpsb
mov al, '$' ; 遇到 $ 表达匹配成功
cmp al, es:[di - 1]
jnz notmatch
push es
mov ax, showdata
mov es, ax
pop bp
pop si
push si
push bp
mov bx, es:[seletw]
shl bx, 1
add bx, offset shwords ; 计算保存新的匹配单词的位置
mov ax, si
mov es:[bx], ax ; 保存单词的地址
inc es:[seletw] ; 计数
pop es
mov cx, 30
pop si ; 取出当前单词的首地址
push si
dispscreen ; 输出匹配的单词
push es
mov ax, showdata ; 光标下移
mov es, ax
inc es:[curp] ; 光标下移
curse es:[curp], 0
pop es
notmatch:
pop si
pop di
pop cx
mov ax, si
add ax, type worddata ; 匹配下一个单词
mov si, ax
loop lop2
push es
mov ax, showdata
mov es,ax
mov ax, 0
cmp es:[seletw], ax
pop es
jnz matchret
lea ax, noword ; 没有匹配到任何单词输出错误
mov si, ax
mov ax, showdata
mov ds, ax
mov cx, 80
dispscreen
matchret:
irp regad, <bp, ds, es, di, si, dx, cx, bx, ax>
pop regad
endm
ret
match endp
code ends
end 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