小弟最近做一实验,要求用汇编编写,由于小弟才疏学浅,只学过C#,对汇编题目一筹莫展,劳烦各位高手帮忙,题目如下:
1 实验题目:查找电话号码phone
2 实验要求:1)要求程序建立一个可存放50项的电话号码表,每项包括人名(20个字符)及电话号码(8个字符)两部分;
2)程序可接收输入人名及相应的电话号码,并把他们加入到电话号码表中。
3)凡有新的输入后,程序应按人名对电话号码表进行重新排序。
4)程序可接收需要查找电话号码的人名,并从电话号码表中查出其电话号 码,再在屏幕上以如下格式显示出来。
name tel。
dkljfa 111111
5)要求有主菜单,至少应有五个以上的独立的模块。
下面是我编出来的程序,可是有错误,大家帮忙看看好吗?
dseg segment
namepar label byte
maxlen db 21
namelen db ?
namefld db 21 dup(?)
telpar label byte
tmaxlen db 9
tellen db ?
telfld db 9 dup(?)
crlf db 13,10,'$'
string1 db '请输入名字:',13,10,'$'
string2 db '请输入电话号码:',13,10,'$'
string3 db 'Do you want a telephone number?(Y/N)','$'
string4 db '------------------------------------------------------------------',13,10,'$'
string5 db '查询(c) 插入(i) 删除(d) 排序(s) 退出(e)',13,10,'$'
endaddr dw ?
messg1 db 'Name?','$'
messg2 db '名字 电话号码',13,10,'$'
messg3 db '查无此记录',13,10,'$'
namectr db 0
b db 0
tel_tab db 50 dup(20 dup(?),8 dup(?))
namesav db 28 dup(?),13,10,'$'
namesav2 db 28 dup(?),13,10,'$'
swapped db 0
dseg ends
cseg segment
main proc far
assume cs:cseg,ds:dseg,es:dseg
start:
push ds
sub ax,ax
push ax
mov ax,dseg
mov ds,ax
mov es,ax
cld
lea di,tel_tab
a20loop:
call input_name
cmp namelen,0
jz a30
call inphone
cmp namectr,50
je a30
call stor_name
jmp a20loop
a30:
cmp namectr,1
jbe a40
call name_show
call contbar
getkey:
mov ah,1
int 21h
cmp al,'c'
je name_check
cmp al,'i'
je name_insert
cmp al,'d'
je name_del
cmp al,'s'
je name_sort2
cmp al,'e'
je a40
name_check:
call input_name
call name_search
jmp getkey
name_insert:
call input_name
call inphone
call stor_name
call name_show
call contbar
jmp getkey
name_del:
call ndel
call name_show
jmp getkey
name_sort2:
call name_sort
jmp getkey
a40:
ret
main endp
input_name proc near
lea dx,string1
mov ah,09
int 21h
mov ah,0ah
lea dx,namepar
int 21h
mov ah,09
lea dx,crlf
int 21h
mov bh,0
mov bl,namelen
mov cx,21
sub cx,bx
b20:
mov namefld[bx],20h
inc bx
loop b20
ret
input_name endp
inphone proc near
lea dx,string2
mov ah,09
int 21h
lea dx,telpar
mov ah,0ah
int 21h
mov ah,09
lea dx,crlf
int 21h
mov bh,0
mov bl,tellen
mov cx,9
sub cx,bx
tel20:
mov telfld[bx],20h
inc bx
loop tel20
ret
inphone endp
stor_name proc near
inc namectr
cld
lea si,namefld
mov cx,20
rep movsb
lea si,telfld
mov cx,8
rep movsb
ret
stor_name endp
name_sort proc near
sub di,56
mov endaddr,di
g20:
mov swapped,0
lea si,tel_tab
g30:
mov cx,20
mov di,si
add di,28
mov ax,di
mov bx,si
repe cmpsb
jbe g40
call h10xchg
g40:
mov si,ax
cmp si,endaddr
jbe g30
cmp swapped,0
jnz g20
ret
name_sort endp
h10xchg proc near
mov cx,28
lea di, namesav
mov si,bx
rep movsb
mov cx,28
mov di,bx
rep movsb
mov cx,28
lea si,namesav
rep movsb
mov swapped,1
ret
h10xchg endp
name_search proc near
mov b,0
push di
mov ch,0
mov cl,20
cld
lea di,tel_tab
n20:
lea si,namefld
repe cmpsb
jne n30
call printline
jmp n40
n30:
inc b
dec namectr
jz n31
add di,cx
add di,8
jmp n20
n31:
lea dx,messg3
mov ah,09h
int 21h
n40:
mov b,di
mov namectr,bl
pop di
ret
name_search endp
printline proc near
sub di,20
mov si,di
lea di,namesav
mov cx,28
rep movsb
mov ah,09
lea dx,messg2
int 21h
mov ah,09
lea dx,namesav
int 21h
ret
printline endp
name_show proc near
push di
lea dx,messg2
mov ah,09h
int 21h
lea si,tel_tab
mov bl,namectr
lk: mov cx,28
lea di,namesav
cld
rep movsb
lea dx,namesav
mov ah,09h
int 21h
dec bl
cmp bl,0
jne lk
pop di
ret
name_show endp
contbar proc near
lea dx,string4
mov ah,09h
int 21h
lea dx,string5
mov ah,09h
int 21h
lea dx,string4
mov ah,09h
int 21h
ret
contbar endp
ndel proc near
call input_name
call name_search
mov al,b
sub al,20
mov di,ax
mov ch,0
mov cl,28
dec namectr
mov al,namectr
mul cl
mov si,ax
cld
rep movsb
mov di,si
lea si,namesav2
mov cx,28
rep movsb
sub ax,28
mov di,ax
ret
ndel endp
cseg ends
end start
[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)