主题:汇编难题
YUOYUO
[专家分:0] 发布于 2010-06-24 12:05:00
请各位高手帮帮忙,这个难了我好几天了,我是个新手,实在感激不尽!
编写程序,实现表的处理:内存单元中有一个ASCII码表,编写程序完成下面的功能:
① 首先输出表的内容;
② 插入一个数据,插入的数据和插入的位置从键盘输入;
③ 对表中的数据进行排序,按升顺或降顺排序可以进行选择;
④ 在表中查找某一个关键字,要查找的关键字从键盘输入;如果找到,输出查找的关键字并给出提示“find”,否则给出提示“no find”;
⑤ 程序执行以后,输出表中的插入以后的内容和排序以后的内容;
⑥ 程序有友好的运行界面;
⑦要求程序能够处理基本的错误信息;
⑧
data segment
line1 db 0ah,0dh,'Please input where you want to insert the a letter or number: ',0ah,0dh,'$'
line2 db 0ah,0dh,'Please input a letter or number:',0ah,0dh,'$'
line3 db 0ah,0dh,'please input a letter or number that you want to find:',0ah,0dh,'$'
right db 'find',0ah,0dh,'$'
wrong db 'no find',0ah,0dh,'$ '
table db 'ietfr8923y7@#%1',0ah,0dh,'$'
table1 db '0000000000000000',0ah,0dh,'$'
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov dx,offset table
mov ah,09h
int 21h
mov dx,offset line1
mov ah,09h
int 21h
mov ah,01h
int 21h
sub al,30h
mov ah,0
mov bx,ax
mov dx,offset line2
mov ah,09h
int 21h
mov ah,01h
int 21h
mov ah,0
mov di,offset table
add di,bx
dec di
mov si,0
mov cx,0
ll: mov bl,[table+si]
mov [table1+si],bl
mov cx,offset [si+table1]
cmp cx,di
jz qq
inc si
jmp ll
qq:mov [table1+si],al
vv: mov bl,[table+si]
mov [table1+si+1],bl
cmp si,15
jz rr
inc si
jmp vv
rr:mov dx,offset table1
mov ah,09h
int 21h
mov si,offset table1
mov cx,16
kk:mov bx,1
mov di,bx
aa:lodsb
cmp al,[table1+di]
jb ee
inc di
cmp [table1],'y'
jz yy
jmp aa
ee: mov bl,[table1+di]
mov [table1+di],al
mov [table1+di-1],bl
inc di
jmp aa
yy:mov dx,offset table1
mov ah,09h
int 21h
mov dx,offset line3
mov ah,09h
int 21h
mov ah,01h
int 21h
mov bl,al
mov si,offset table1
mov dl,16
ff:lodsb
cmp al,bl
jz gg
dec dl
jnz ff
jmp oo
gg: mov dx,offset right
mov ah,09h
int 21h
jmp xx
oo:mov dx,offset wrong
mov ah,09h
int 21h
jmp xx
xx:mov ah,4ch
int 21h
code ends
end start
回复列表 (共1个回复)
沙发
YUOYUO [专家分:0] 发布于 2010-06-24 12:22:00
data segment
line1 db 0ah,0dh,'Please input where you want to insert the a letter or number: ',0ah,0dh,'$'
line2 db 0ah,0dh,'Please input a letter or number:',0ah,0dh,'$'
line3 db 0ah,0dh,'please input a letter or number that you want to find:',0ah,0dh,'$'
right db 'find',0ah,0dh,'$'
wrong db 'no find',0ah,0dh,'$ '
table db 'ietfr8923y7@#%1',0ah,0dh,'$'
table1 db '0000000000000000',0ah,0dh,'$'
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov dx,offset table
mov ah,09h
int 21h
mov dx,offset line1
mov ah,09h
int 21h
mov ah,01h
int 21h
sub al,30h
mov ah,0
mov bx,ax
mov dx,offset line2
mov ah,09h
int 21h
mov ah,01h
int 21h
mov ah,0
mov di,offset table
add di,bx
dec di
mov si,0
mov cx,0
ll: mov bl,[table+si]
mov [table1+si],bl
mov cx,offset [si+table1]
cmp cx,di
jz qq
inc si
jmp ll
qq:mov [table1+si],al
vv: mov bl,[table+si]
mov [table1+si+1],bl
cmp si,15
jz rr
inc si
jmp vv
rr:mov dx,offset table1
mov ah,09h;这一块是为了插入一个字符,方法是假如输入的位置是2的话就是把位置1以前的给table1然后输入的内容al给table1的第二个位置,一次把table的第二个位置
int 21h;给table2的第三个位置,一次把table的第三个位置给table2的第四个位置然后一直循环到table的第一个为table里的最大值为止
mov si,offset table1
mov cx,16
kk:mov bx,1
mov di,bx
aa:lodsb
cmp al,[table1+di]
jb ee
inc di
cmp [table1],'y'
jz yy
jmp aa
ee: mov bl,[table1+di]
mov [table1+di],al
mov [table1+di-1],bl
inc di
jmp aa
yy:mov dx,offset table1
mov ah,09h
int 21h;以上是冒泡法,就是第一个与第二个比较把大的放在前面小的在后,然后是第二个与第三个比较把大的放在前面小的在后,循环一次后最小的就在最后一个了
mov dx,offset line3;然后再按照这个方法循环一次倒数第二个就是第二小的了,总共循环15次,排序完成
mov ah,09h
int 21h
mov ah,01h
int 21h
mov bl,al
mov si,offset table1
mov dl,16
ff:lodsb
cmp al,bl
jz gg
dec dl
jnz ff
jmp oo
gg: mov dx,offset right
mov ah,09h
int 21h
jmp xx
oo:mov dx,offset wrong
mov ah,09h
int 21h
jmp xx;以上是查找字符串很好理解的
xx:mov ah,4ch
int 21h
code ends
end start
这是一些解释,谢谢各位来指点
我来回复