我已经查看了如何比较两个字符串程序集,并且我正在尝试逐个字符进行比较,直到一个字符不匹配并且我似乎无法让我的代码按我想要的方式运行。
我正在制作一个简单的 shell,我从 help 命令开始:
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 中断来实现输入和输出。
尽管输入了“帮助”,但它每次都会输出“未知命令”。