【发布时间】:2017-11-18 12:37:33
【问题描述】:
我想将存储在寄存器si 中的用户输入与另一个字符串进行比较。
顺便说一句,我正在使用 FASM。这是用户输入后我的代码。
如果我使用repe cmpsb 命令,我知道我必须使用额外的段,但我不知道如何使用。而repe cmpsb 命令不适用于此代码。
.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
【问题讨论】:
-
您不仅需要指定汇编程序,还需要指定目标平台。例如,在 linux 中,这是完全错误的代码,因为它既没有使用 32b 也没有使用 64b 指针。那么如果你说这是 DOS 16b,我们需要看看你是如何定义数据的,为了你自己添加好问题,你应该尝试自己产生minimal reproducible example,例如你当前的代码确实设置了
di两次,但不清楚si中的内容(要么设置它,要么添加明确的评论)。 -
这里有一篇文章解释了
segment:offset在 16b 实模式下的寻址(为了更好地了解,es和ds的用途):thestarman.pcministry.com/asm/debug/Segments.html