2016-06-14 14:53

# 小弟初学汇编，汇编问题！！！！

buf1 db 50 dup('\$') ;最大字符数50
buf2 db 20 dup('\$') ;查找最大字符数20
tishi1 db 'Please input the string:',0dh,0ah,'\$'
tishi2 db 'Please input the string you want to find:',0dh,0ah,'\$'
tishi3 db 'Find:','\$'
tishi4 db 'Not Find:','\$'
data ends

code segment
assume cs:code, ds:data

start: mov ax,data
mov ds,ax
mov cx,0
mov bx,0
mov si,2
mov di,2

``````lea dx,tishi1
mov ah,09h
int 21h         ;输出提示1

lea dx,buf1
mov ah,0ah
int 21h         ;输入字符串

mov dl,0ah
mov ah,02h
int 21h         ;回车换行

lea dx,tishi2
mov ah,09h
int 21h         ;输出提示2

lea dx,buf2
mov ah,0ah
int 21h         ;输入字符串

mov dl,0ah
mov ah,02h
int 21h         ;回车换行

lea si,buf1+2
lea di,buf2+2
mov ax,0
jmp z
``````

x: inc cx
inc di
y: inc si
z: mov ah,buf1[si]
mov al,buf2[di]
cmp al,'\$'
je yes
cmp ah,al
je x

``````cmp ah,'\$'
je no
sub si,cx
sub di,cx
mov cx,0
jmp y
``````

yes:

lea dx,tishi3
mov ah,09h
int 21h ;输出提示3

``````lea dx,buf2+2
mov ah,09h
int 21h

mov dl,0ah
mov ah,02h
int 21h         ;回车换行
jmp exit
``````

no:
lea dx,tishi4
mov ah,09h
int 21h ;输出提示4

``````lea dx,buf2+2
mov ah,09h
int 21h

mov dl,0ah
mov ah,02h
int 21h         ;回车换行
``````

exit: mov ah,4ch
int 21h

code ends
end start

123

• 点赞
• 写回答
• 关注问题
• 收藏
• 邀请回答