📄 dagl1.asm
字号:
data segment
menu db 13,10
db 13,10
db '******************************************************',13,10
db 'Please choose these following choices:',13,10
db '(1)L:List records (2)S:Search record',13,10
db '(3)A:Add record (4)D:Delete record',13,10
db '(5)Q:Quit',13,10
db '******************************************************',13,10
db 13,10
db 'Your choice is:','$'
continue db 13,10,'Please press any key to continue.','$'
L_TAB db 13,10,'ID NAME SEX AGE',13,10,'$'
L_SUC db 13,10,'List succeeding.','$'
L_FAIL db 13,10,'Fail:Nothing in this table.','$'
S_TAB db 13,10,'Searching by ID. ',13,10,'Please input the ID number:','$'
S_SUC db 13,10,'Search succeeding.','$'
S_ERR_1 equ L_FAIL
S_ERR_2 db 13,10,'Fail:There is no such record in this table.','$'
A_TAB db 13,10,'Please input the new record:','$'
A_ID db 13,10,'ID number:','$'
A_NAME db 13,10,'Name:','$'
A_SEX db 13,10,'Sex:','$'
A_AGE db 13,10,'Age:','$'
A_SUC db 13,10,'Add succeeding.','$'
A_EA dw 0 ;存放新记录的首地址,表满时为-1
A_ERR_1 equ L_FAIL
A_ERR_2 db 13,10,'Fail:This ID is existing.','$'
D_TAB db 13,10,'Deleting record by ID.',13,10,'Please input the ID number:','$'
D_ASK db 13,10,'Do you really want to remove this record ?(Y/N)','$'
D_SUC db 13,10,'Delete succeeding.','$'
D_ERR_1 equ L_FAIL
D_ERR_2 equ S_ERR_2
D_ERR_3 db 13,10,'Delete is rejecting.','$'
QUIT db 13,10
db 13,10,'Thanks for your using.'
db 13,10
db 13,10,'Press any key to exit.','$'
;开辟10个记录的存储区
num equ 10 ;记录数常数
TAB db num dup(0,10 dup(?),3 dup(' '),8 dup(?),3 dup(' '),?,6 dup(' '),?,?,?,13,10,'$')
LEN db 0 ;记录非空记录数
TEM_ID db 10 dup(?) ;暂存ID
L_ID equ 10 ;ID长度
L_NAM equ 8 ;姓名长度
L_SEX equ 1 ;性别长度
L_AGE equ 3 ;年龄长度
L_REC equ 38 ;记录长度
L_ERR db 0 ;列表错误返回码
S_ERR db 0 ;查找错误返回码
A_ERR db 0 ;插入错误返回码
D_ERR db 0 ;删除错误返回码
data ends
stack segment stack
db 100 dup(0)
top db ?
stack ends
code segment
assume cs:code,ds:data,es:data,ss:stack
;
start: mov ax,data
mov ds,ax
mov es,ax
mov ax,stack
mov ss,ax
lea sp,top
;
distit: lea dx,menu
mov ah,9
int 21h
;
choose: mov ah,7
int 21h
ch_l: cmp al,'L'
jnz ch_s
jmp op_l
ch_s: cmp al,'S'
jnz ch_a
jmp op_s
ch_a: cmp al,'A'
jnz ch_d
jmp op_a
ch_d: cmp al,'D'
jnz ch_q
jmp op_d
ch_q: cmp al,'Q'
jnz choose
jmp op_q
;显示操作
op_l: mov dl,al
mov ah,2
int 21h
op_l_cr: mov ah,7
int 21h
cmp al,13
jnz op_l_cr
;
call list_records
cmp L_ERR,1
jz op_l_err
mov ah,7
int 21h
jmp distit
;
op_l_err:lea dx,L_FAIL
mov ah,9
int 21h
lea dx,continue
mov ah,9
int 21h
mov ah,7
int 21h
jmp distit
;查找操作
op_s: mov dl,al
mov ah,2
int 21h
op_s_cr: mov ah,7
int 21h
cmp al,13
jnz op_s_cr
;
call search_record
cmp S_ERR,1
jz op_s_e1
cmp S_ERR,2
jz op_s_e2
mov ah,7
int 21h
jmp distit
;
op_s_e1: lea dx,S_ERR_1
mov ah,9
int 21h
lea dx,continue
mov ah,9
int 21h
mov ah,7
int 21h
jmp distit
op_s_e2: lea dx,S_ERR_2
mov ah,9
int 21h
lea dx,continue
mov ah,9
int 21h
mov ah,7
int 21h
jmp distit
;插入操作
op_a: mov dl,al
mov ah,2
int 21h
op_a_cr: mov ah,7
int 21h
cmp al,13
jnz op_a_cr
;
call add_record
cmp A_ERR,1
jz op_a_e1
cmp A_ERR,2
jz op_a_e2
mov ah,7
int 21h
jmp distit
;
op_a_e1: lea dx,A_ERR_1
mov ah,9
int 21h
lea dx,continue
mov ah,9
int 21h
mov ah,7
int 21h
jmp distit
op_a_e2: lea dx,A_ERR_2
mov ah,9
int 21h
lea dx,continue
mov ah,9
int 21h
mov ah,7
int 21h
jmp distit
;删除操作
op_d: mov dl,al
mov ah,2
int 21h
op_d_cr: mov ah,7
int 21h
cmp al,13
jnz op_d_cr
;
call delete_record
cmp D_ERR,1
jz op_d_e1
cmp D_ERR,2
jz op_d_e2
cmp D_ERR,3
jz op_d_e3
mov ah,7
int 21h
jmp distit
;
op_d_e1: lea dx,D_ERR_1
mov ah,9
int 21h
lea dx,continue
mov ah,9
int 21h
mov ah,7
int 21h
jmp distit
op_d_e2: lea dx,D_ERR_2
mov ah,9
int 21h
lea dx,continue
mov ah,9
int 21h
mov ah,7
int 21h
jmp distit
op_d_e3: lea dx,D_ERR_3
mov ah,9
int 21h
lea dx,continue
mov ah,9
int 21h
mov ah,7
int 21h
jmp distit
;退出操作
op_q: mov dl,al
mov ah,2
int 21h
op_q_cr: mov ah,7
int 21h
cmp al,13
jnz op_q_cr
;
lea dx,QUIT
mov ah,9
int 21h
mov ah,7
int 21h
;
mov ah,4ch
int 21h
;*************************************
;功能:输出全表记录
;破坏寄存器:无
;返回值:L_ERR(1)当表空时,L_ERR=1
;*************************************
;
list_records proc near
push ax
push bx
push cx
push dx
push di
;
cmp LEN,0
jnz list1
mov L_ERR,1 ;表空
jmp end_l
;表非空
list1: lea dx,L_TAB
mov ah,9
int 21h
;
mov cl,0
mov bx,0
mov di,1
mov ah,9
list2: cmp byte ptr TAB[bx],0
jz list3 ;转移则为空记录
inc cl ;非空记录
lea dx,TAB[bx][di]
int 21h
list3: add bx,L_REC ;下一记录首地址
cmp cl,LEN
jnz list2 ;非空记录尚未显示完转移
;
mov L_ERR,0
;
lea dx,L_SUC
mov ah,9
int 21h
lea dx,continue
mov ah,9
int 21h
;
end_l: pop di
pop dx
pop cx
pop bx
pop ax
ret
list_records endp
;
;**********************************************
;功能:根据ID号查找表内记录
;破坏寄存器:无
;返回值:S_ERR(1)当表空时,S_ERR=1
; (2)当表内无匹配记录时,S_ERR=2
;**********************************************
;
search_record proc near
push ax
push bx
push cx
push dx
push si
push di
push bp
;
cmp LEN,0
jnz search1
mov S_ERR,1 ;表空
jmp end_s
;表非空
search1: lea dx,S_TAB
mov ah,9
int 21h
;输入ID串并暂存
mov si,0
search2: mov ah,7
int 21h
cmp al,'0'
jb search2
cmp al,'9'
ja search2
mov dl,al
mov ah,2
int 21h
mov TEM_ID[si],al
inc si
cmp si,L_ID
jnz search2
;
search3: mov ah,7
int 21h
cmp al,13
jnz search3
;与非空记录比对
mov bl,0
cld
mov si,(offset TAB)+1
search4: mov bp,si
cmp byte ptr [si-1],1
jnz search5 ;转移则为空记录
inc bl ;非空记录
lea di,TEM_ID
mov cx,L_ID
repz cmpsb
jz search7 ;转则有匹配记录
mov si,bp
search5: add si,L_REC ;下一记录首地址
cmp bl,LEN
jz search6 ;所有记录均已做比对无匹配则转
jmp search4
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -