回 帖 发 新 帖 刷新版面

主题:关于查找的程序的问题``````求求教

从键盘输入一串字符 在这串字符中是否有字"student"

回复列表 (共8个回复)

沙发

data    segment
    msg1 db 10,?,10 dup(?)
    msg2 db 'error!$'
data    ends
code    segment
    assume cs:code,ds:data
start:    mov ax,data
    mov ds,ax
    lea dx,msg
    mov ah,0ah
    int 21h
    mov al,msg+1
    cbw
    mov si,ax
    mov al,msg1[si+2]
    cmp al,'s'
    jne exit
    inc si
    mov al,msg1[si+2]
    cmp al,'t'
    jne
    ……
    ……
    ……
    ……
    ……
exit:    lea dx,msg2
    mov ah,09h
    int21h
    mov ah,4ch
    int 21h
code    ends
    end start    
中间的省略号部分你抄模仿前面的就可以了

板凳

我也想过这样做````感觉好长和麻烦
我想过
1)这样的有没有可能将一串字符放在一个寄存器在与输入的比较
2)还有一种想法`就是这样的在找到第一字符"s"时我想与最后一个比较是否有"t"
再接着比较T和n```````
这两种方法和你的方法好???同可不可以实行?

3 楼

[quote]data    segment
    msg1 db 10,?,10 dup(?)
    msg2 db 'error!$'
data    ends
code    segment
    assume cs:code,ds:data
start:    mov ax,data
    mov ds,ax
    lea dx,msg
    mov ah,0ah
    int 21h
    mov al,msg+1
    cbw
    mov si,ax
    mov al,msg1[si+2]
    cmp al,'s'
    jne exit
    inc si
    mov al,msg1[si+2]
    cmp al,'t'
    jne
    ……
    ……
    ……
    ……
    ……
exit:    lea dx,msg2
    mov ah,09h
    int21h
    mov ah,4ch
    int 21h
code    ends
    end start    
中间的省略号部分你抄模仿前面的就可以了[/quote]

4 楼

start:    mov ax,data
    mov ds,ax
    lea dx,msg
    mov ah,0ah
    int 21h
    mov al,msg+1
    cbw
    mov si,ax
这里有点错误
改start:    mov ax,data
    mov ds,ax
    lea dx,msg1
    mov ah,0ah
    int 21h
    mov al,msg1
    cbw
    mov si,msg1

5 楼


你的好象不太行`
假如第一个刚好不是"student"字符串而是从第二个才是"student"那样你的程序就不可以找出有无"student"这个字符串了

举例说:
输入 a student 
输出 error

6 楼


LZ发贴没把意思说清楚。
下面这段程序就行了

data    segment
    msg db 'Please type your words!',10,13,'$'
    words db 100,?,100 dup(?)
    error db 'Error!please type your words again',10,13,'$'
data    ends
code    segment
    assume cs:code,ds:data
start:    mov ax,data
    mov ds,ax
    lea dx,msg
    mov ah,09h
    int 21h
next:    lea dx,words
    mov ah,0ah
    int 21h
    mov dl,0ah
    mov ah,02h
    int 21h
    mov dl,0dh
    mov ah,02h
    int 21h
    mov cl,words+1
    cmp cl,7
    jb err
    mov si,2
s1:    mov al,words[si]
    inc si
    dec cl
    jz err
c1:    cmp al,'s'
    jne s1
c2:    mov al,words[si]
    inc si
    dec cl
    cmp al,'t'
    jne s1
c3:    mov al,words[si]
    inc si
    dec cl
    cmp al,'u'
    jne s1
c4:    mov al,words[si]
    inc si
    dec cl
    cmp al,'d'
    jne s1
c5:    mov al,words[si]
    inc si
    dec cl
    cmp al,'e'
    jne s1
c6:    mov al,words[si]
    inc si
    dec cl
    cmp al,'n'
    jne s1
c7:    mov al,words[si]
    inc si
    dec cl
    cmp al,'t'
    jne s1
    jmp exit
err:    lea dx,error
    mov ah,09h
    int 21h
    jmp next
exit:    mov ah,4ch
    int 21h
code    ends
    end start

7 楼

[em2]
感谢你的帮助
下次我会注意一下``把话说清楚``````
谢谢了````

8 楼

?

我来回复

您尚未登录,请登录后再回复。点此登录或注册