Assembly 如何比较汇编中的字符串?
我已经看过了,我正在尝试一个字符一个字符地比较,直到一个字符不匹配,我似乎无法让我的代码按我想要的方式运行 我正在制作一个简单的shell,并从help命令开始:Assembly 如何比较汇编中的字符串?,assembly,compare,user-input,16-bit,real-mode,Assembly,Compare,User Input,16 Bit,Real Mode,我已经看过了,我正在尝试一个字符一个字符地比较,直到一个字符不匹配,我似乎无法让我的代码按我想要的方式运行 我正在制作一个简单的shell,并从help命令开始: parseInput: mov ah, 0x0e mov bh, [bx] mov bl, s_HELP_COMMAND parseInputLoop: cmp bh, bl jne parseInputReturn cmp bh, 0
parseInput:
mov ah, 0x0e
mov bh, [bx]
mov bl, s_HELP_COMMAND
parseInputLoop:
cmp bh, bl
jne parseInputReturn
cmp bh, 0
je parseInputEqual
mov al, bh
int 0x10
mov al, bl
int 0x10
call newLine
inc bh
inc bl
jmp parseInputLoop
parseInputEqual:
mov bx, s_HELP_OUTPUT
call printStr
parseInputReturn:
mov bx, s_UNKNOWN_COMMAND
call printStr
call newLine
ret
s_HELP_COMMAND: db 'help', 0
s_HELP_OUTPUT: db 'help - list commands.', 0
s_UNKNOWN_COMMAND: db 'Unknown command. Type "help" to see all commands', 0
它从堆栈中读取用户输入的字符串。以下是用户输入代码:
inputLoop:
call getKeyPress ; wait for the user to press a key
cmp bx, 0xD ; 0xD = 13 = ASCII code for enter
je inputLoopExit ; exit the inputLoop if the pressed key
; is enter
call printChar ; print the pressed key so the user can
; see what they've typed
push bx ; push the pressed key onto the stack so
; that it can be parsed later
jmp inputLoop
inputLoopExit:
call newLine
push 0 ; put 0 onto the stack
mov bx, bp ; store the start of the stack in bx so
; that parseInput can read the inputed
; string
call parseInput
它使用BIOS中断来实现输入和输出
尽管输入了“帮助”,但每次都会输出“未知命令”。
mov bh, [bx]
mov bl, s_HELP_COMMAND
第一行从…加载一个字节。。。无论bp
指向什么。我想这是一个输入字符(?)。第二行加载s\u HELP\u命令
的地址(地址的偏移部分)的低位字节。这似乎没有用
也许您打算mov-bl,[s\u HELP\u命令]
。这将为您提供字符“h”。增加它将得到“g”,而不是命令中的下一个字符(“e”)
可能还有更复杂的情况<代码>[bp]默认为[ss:bp]
[bx]
默认为[ds:bx]
,除非ss
=ds
(可能是真的-您不显示该部分)它们不会引用内存中的同一位置
我建议您重新思考整个
parseInput
例程(可能还有以前的例程)。采取更小的步骤 您的parseInputLoop
从未读取任何字符串,因此它没有进行字符串比较。整个代码似乎太复杂了。只需将输入字符存储在缓冲区中,然后使用repe cmpsb
将缓冲区内容与一些字符串进行比较。