How to compare two lines in x86 assembly with FASM?

I want to compare the user input stored in a register siwith another line.
By the way, I use FASM. Here my code is still after user input.
If I use the command repe cmpsb, I know that I need to use an additional segment, but I do not know how to do it. And the team repe cmpsbdoes not work with this code.

.input_done:
   cmp si, 0
   je no_input
   jmp short .compare_input


.compare_input:
    mov cx, 20 ;For the repe cmpsb command.
    cld
    mov di, info ;The string I want to compare.
    mov es, di
    mov di, info
    repe cmpsb
    cmp cx, 0
    je showinfo
.showinfo:
    ... ;The output string if both string are the same.

info db "info", 0
+4
source share
1 answer
mov di, info ;The string I want to compare.
mov es, di

For a simple program, it is probably true that both lines will be stored in the same memory segment. Just put the value DSin ES.

...
push ds
pop  es
mov  di, info
...

And the team repe cmpsbdoes not work with this code.

CX 20, ( "" ) 4 . , .


, , , . , .
, CX.

; String1 pointer in DS:SI, length in CX
; String2 pointer in ES:DI, length in DX

cmp  cx, dx
jne  NotEqual
repe cmpsb
jne  NotEqual
Equal:       ; .showinfo:
...          ; The output string if both string are the same.
; Don't fall through here!!!
NotEqual:
...
+2

Source: https://habr.com/ru/post/1689497/


All Articles