HeiGe__ 2016-11-09 16:48 采纳率: 50%
浏览 3013
已采纳

汇编scasb问题,字符串查找问题

题目要求:
1) 把从LIST 到LIST+316中的字符串传送到BLK到BLK+316 中去;
2) 在BLK到BLK+100中查找字符“cqu”字符串,并记下“CQU”字符串出现的起始位置到BX中。
说明,LIST 到LIST+100的内容(from:http://study.cqu.edu.cn/IndexOfEnglish/Index)为:
Chongqing University (CQU) is a key national university and a member of the “Excellence League”, located in Chongqing, Southwest China. It is also one of the “211 Project" and "985 Project” universities with full support in construction and development from the central government and Chongqing Municipal Government.

我是这样写的:

 data segment
     LIST   db   'Chongqing University (CQU) is a key national university and a member of the “Excellence League”,'
                db  'located in Chongqing, Southwest China. It is also one of the “211 Project" '
                 db   'and "985 Project” universities with full support in construction and develop'
                 db       ' ment from the central government and Chongqing Municipal Government.$'
     CQU   db   'CQU'
data ends
extra segment
     BLK    db    316 dup(?)
extra ends
stack segment
stack ends
code segment
     assume cs:code,ds:data,ss:stack
start:
     mov ax, data
     mov ds, ax
     mov ax, extra
     mov es, ax
     lea    si, LIST
     lea    di, BLK
     mov cx, 316
     cld
     rep   movsb
     mov al, 'C'
     lea   si, LIST-1
find:
     inc si
     repne   scasb
     jnz  check
check:
     mov cx, 3
     repz cmpsb
     jz     stop
     jnz   find
stop:
     mov bx, si
     mov ah, 4ch
     int 21h
code ends
end start

字符串的传递没有问题,但是查找字符串就出问题。
我的思路是,在find中,先将每一个字符与C判断,如果字符是C的话,就跳转到check中,在check中在与字符串CQU判断,如果不是CQU的话则返回到find中。现在的问题是scasb查找到C时,返回的结果不为0。
求大神解答,另外我的思路有问题吗?求更好的思路。

  • 写回答

2条回答 默认 最新

  • HeiGe__ 2018-10-18 16:06
    关注

    以上解答错误,重新修正(鉴于三年了,年年都有人来问这个题,修正一下)
    正解

     data segment
         LIST   db   'Chongqing University (CQU) is a key national university and a member of the “Excellence League”,'
                    db  'located in Chongqing, Southwest China. It is also one of the “211 Project" '
                     db   'and "985 Project” universities with full support in construction and develop'
                     db       ' ment from the central government and Chongqing Municipal Government.$'
         CQU   db   'CQU'
    data ends
    extra segment
         BLK    db    316 dup(?)
    extra ends
    stack segment
    stack ends
    code segment
         assume cs:code,ds:data,ss:stack
    start:
         mov ax, data
         mov ds, ax
         mov ax, extra
         mov es, ax
         lea    si, LIST
         lea    di, BLK
         mov cx, 316
         cld
         rep   movsb
         lea    si, CQU
         lea    di, BLK
         mov  ax, si
         add   ax, 4
         mov  cx, 100
         mov  dx, ax
    cycle:
         cld
         repe cmpsb
         sub dx, si
         jz match
         lea si, CQU
         mov dx, ax
         loop cycle
    
    match:
         mov bx, di 
         sub  bx, 4h
         mov ah, 4ch
         int 21h
    code ends
    end start
    
    

    结果如下:
    字符串转移成功
    图片说明
    查找字符串成功,BX中存储内容为CQU的起始位置为16H=22D
    图片说明

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP