如何组装比较两个字符串 [英] How to compare two strings assembly

查看:173
本文介绍了如何组装比较两个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我如何比较汇编语言两个字符串,I`ve写的followign,但它似乎并没有工作。

 假设CS:code,DS:数据数据段
sirlung DBabcdjjj
lungimelung EQU $ -sirlung
sirscurt DB奥比
lungimescurt EQU $ -sirscurt
exista DBExista!$
nuexista DBNU exista!$
iesire DBApasa进入pentru iesire!$
数据结束code段
开始:
MOV AX,数据
MOV DS,AXMOV BX,偏移sirlung
MOV DI,抵消sirscurt
十二月BX
推BX
推迪
MOV DX,lungimelung
MOV SI,lungimescurt
bucla1:
    流行迪
    流行BX
    INC BX
    MOV人,sirlung [BX]
    MOV CL,sirscurt [二]    CMP人,CL
    JNE bucla1
    推BX
    推迪
    JE bucla2
    CMP BX,DX
    JA sfarsit_nu_exista
bucla2:
    INC BX
    INC迪
    MOV人,sirlung [BX]
    MOV CL,sirscurt [二]
    CMP人,CL
    JNE bucla1
    CMP DI,SI
    JL sfarsit_exista
    宰bucla2sfarsit_exista:
MOV DX,偏移exista
MOV啊,09H
INT 21H
MOV啊,0AH
MOV DX,偏移iesire
INT 21H
MOV AX,4c00h
INT 21Hsfarsit_nu_exista:
MOV DX,偏移nuexista
MOV啊,09H
INT 21H
MOV啊,0AH
MOV DX,偏移iesire
INT 21H
MOV AX,4c00h
INT 21Hcode端
年底启动


解决方案

我有同样的问题,当我在学校写作ASM,年前。我遇到的问题是,我想这个词退出与用户条目进行比较。如果他们键入退出,应用程序退出。如果他们输入任何东西,然后一个信息出现,告诉他们有一个错误的条目。

我解决这个问题的方法是比较字符串的字符逐个字符,直到字符不再匹配,反之亦然。

这也可能是一些使用。以下是关于在汇编语言字符串比较一些code例子:<一href=\"http://www.daniweb.com/software-development/assembly/threads/58667/assembly-language-comparing-strings\" rel=\"nofollow\">http://www.daniweb.com/software-development/assembly/threads/58667/assembly-language-comparing-strings

您可能也想看看这篇文章的汇编语言与常规的前pressions(正则表达式)的正防爆pressions和装配

Could anyone tell me how to compare two strings in assembly language, I`ve written the followign, but it does not seem to work.

assume cs:code, ds:data

data segment
sirlung db "abcdjjj"
lungimelung equ $-sirlung
sirscurt db "aby"
lungimescurt equ $-sirscurt
exista db "Exista!$"
nuexista db "NU exista!$"
iesire db "Apasa enter pentru iesire!$"


data ends

code segment
start:
mov ax,data
mov ds,ax

mov bx,offset sirlung
mov di,offset sirscurt
dec bx
push bx
push di
mov dx,lungimelung
mov si,lungimescurt
bucla1:
    pop di
    pop bx
    inc bx
    mov al,sirlung[bx]
    mov cl,sirscurt[di]

    cmp al,cl
    jne bucla1
    push bx
    push di
    je bucla2
    cmp bx,dx
    ja sfarsit_nu_exista
bucla2:
    inc bx
    inc di
    mov al,sirlung[bx]
    mov cl,sirscurt[di]
    cmp al,cl
    jne bucla1      
    cmp di,si
    jl sfarsit_exista
    jae bucla2





sfarsit_exista:
mov dx,offset exista
mov ah,09h
int 21h
mov ah, 0ah
mov dx,offset iesire
int 21h
mov ax,4c00h
int 21h

sfarsit_nu_exista:
mov dx,offset nuexista
mov ah,09h
int 21h
mov ah, 0ah
mov dx,offset iesire
int 21h
mov ax,4c00h
int 21h

code ends
end start

解决方案

I had the same problem when I was writing asm in school, years ago. The problem I encountered was that I wanted to compare the word "exit" with a user entry. If they typed "exit", the application quit. If they typed anything else, then a message appeared telling them there was an erroneous entry.

The way I solved the issue was to compare the strings character-by-character, until the characters no longer matched, or vice-versa.

This also might be of some use. Here are some code examples relating to string comparison in assembly language: http://www.daniweb.com/software-development/assembly/threads/58667/assembly-language-comparing-strings

You might also want to look at this article relating to regular expressions (regex) in assembly language: Regular Expressions and Assembly

这篇关于如何组装比较两个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆