汇编语言 给定一个字符串:this is a computer,从键盘任意输入一个字符,在字符串搜索该字符是否存在,

如果存在则显示其位置,否则显示"N"

调试通过!
DATAS SEGMENT
str1 db 'this is a computer$'
str2 db 0dh,0ah,'$'
DATAS ENDS
STACKS SEGMENT
;此处输入堆栈段代码
STACKS ENDS
CODES SEGMENT
ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
MOV AX,DATAS
MOV DS,AX

mov ah,1 ;等待输入
int 21h

push ax
lea dx,str2 ;回车换行
mov ah,9
int 21h
pop ax

lea si,str1
s1: ;查找
cmp byte ptr[si],'$'
jz s5
cmp al,[si]
jz s2
inc si
jmp s1
s2: ;找到输出
mov ax,si
inc ax

xor dx,dx
xor cx,cx
s3:
mov bl,10
div bl
inc cx
mov dl,ah
mov ah,0
push dx
cmp al,0
jnz s3
s4:
pop dx
add dl,30h
mov ah,2
int 21h
loop s4
jmp s6
s5: ;未找到输出
mov dl,'N'
mov ah,2
int 21h

s6:
mov ah,0
int 16h

MOV AH,4CH
INT 21H
CODES ENDS
END START
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答
大家正在搜