求汇编语言代码!在一个字符串中查找某个字符第一次出现的位置

将题目写成一个过程,该过程传递两个参数1.要查找的字符串2,串的地址。邮箱956332500@qq.com... 将题目写成一个过程,该过程传递两个参数1.要查找的字符串2,串的地址。邮箱956332500@qq.com 展开
 我来答
永恒pascal
2017-05-21 · TA获得超过4358个赞
知道大有可为答主
回答量:3902
采纳率:93%
帮助的人:730万
展开全部
        DATA  SEGMENT
        STR1  DB        'shfskldjfiuiruiyweurwgteuiwiX',0
        ; 以0结尾的字符串,即类似c语言的字符串        
       CHAR1  DB        'X'
        DATA  ENDS

        CODE  SEGMENT
              ASSUME    CS:CODE
      START:
              MOV       AX,SEG DATA
              MOV       DS,AX
              MOV       ES,AX
              LEA       DI,STR1
              MOV       AL,BYTE PTR DS:CHAR1
              CALL      FIND
              CALL      DISPAXS
              MOV       AH,4CH
              INT       21H
  ; ========================================
        FIND  PROC      NEAR
              ; al 为要查找的字符 
              ; di 为目的串的偏移地址                     
              MOV       DX,AX
              MOV       SI,DI
              MOV       AL,0
              MOV       CX,0
        @F1:
              CMP       AL,ES:[DI]
              JE        @F2
              INC       CX
              INC       DI
              JMP       @F1
        @F2:
              MOV       AX,DX
              MOV       DI,SI
              MOV       BX,CX
        @F3:
              CMP       AL,ES:[DI]
              JE        @F4
              INC       DI
              LOOP      @F3
        @F4:
              CMP       CX,0
              JE        @F5
              SUB       BX,CX
              MOV       AX,BX
              RET
        @F5:
              MOV       AX,-1
              RET
              ;  当返回0时,表示第1个元素匹配 
              ;  当返回n-1时,表示第n个元素匹配 
              ;  当返回 -1 时,表示未找到   
        FIND  ENDP
 ;====================================
 ; 将要显示的有符号数置于 ax 中
     DISPAXS  PROC      NEAR
              PUSH      AX
              PUSH      BX
              PUSH      CX
              PUSH      DX
              PUSH      SI
              PUSH      DI
              PUSH      BP
              PUSH      DS
              PUSH      ES
              PUSHF
              PUSH      CS
              POP       DS
              PUSH      CS
              POP       ES
              MOV       CX,6
              LEA       DI,DISPAXSS
   @DISPAXS:
              MOV       BYTE PTR [DI],32
              INC       DI
              LOOP      @DISPAXS
              PUSH      AX
              MOV       DL,32
              MOV       AH,2
              INT       21H
              POP       AX
              MOV       BYTE PTR NZS,0
              MOV       BYTE PTR SIGNS,0
              CMP       AX,0
              JGE       @DISPAXS0
              MOV       BYTE PTR SIGNS,1
              NEG       AX
  @DISPAXS0:
              PUSH      AX
              LEA       SI,DIVARRS
              LEA       DI,DISPAXSS
              INC       DI
              MOV       CX,5
  @DISPAXS1:
              POP       AX
              MOV       DX,0
              MOV       BX,[SI]
              DIV       BX
              PUSH      DX
              CMP       AL,0
              JNE       @DISPAXS2
              CMP       BYTE PTR NZS,1
              JE        @DISPAXS2
              CMP       CX,1
              JE        @DISPAXS2
              MOV       DL,20H
              JMP       @DISPAXS3
  @DISPAXS2:
              ADD       AL,30H
              MOV       DL,AL
              MOV       BYTE PTR NZS,1
  @DISPAXS3:
              MOV       BYTE PTR[DI],DL
              INC       SI
              INC       SI
              INC       DI
              LOOP      @DISPAXS1
              POP       DX

              CMP       BYTE PTR SIGNS,1
              JNE       @DISPAXS6
              LEA       SI,DISPAXSS
              ADD       SI,5
  @DISPAXS4:
              CMP       BYTE PTR [SI],32
              JE        @DISPAXS5
              DEC       SI
              JMP       @DISPAXS4
  @DISPAXS5:
              MOV       BYTE PTR [SI],'-'
  @DISPAXS6:
              LEA       DX,DISPAXSS
              MOV       AH,9
              INT       21H
              POPF
              POP       ES
              POP       DS
              POP       BP
              POP       DI
              POP       SI
              POP       DX
              POP       CX
              POP       BX
              POP       AX
              RET
     DIVARRS  DW        10000,1000,100,10,1
         NZS  DB        0
       SIGNS  DB        0
    DISPAXSS  DB        32,32,32,32,32,32,'$'
     DISPAXS  ENDP
; =============================================     
        CODE  ENDS
              END       START
追问
可以注释一下吗,因为我不太看得懂,谢谢你
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式