나는 How to compare two strings assembly을 보았고 문자가 일치하지 않아서 내가 원하는 방식으로 코드를 작동시킬 수 없을 때까지 문자로 문자를 비교하려고합니다.어셈블리에서 문자열을 비교하는 방법은 무엇입니까?
나는 간단한 쉘을 그리고 난 도움말 명령을 시작 했어 :
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 인터럽트를 사용합니다.
'help'를 입력 할 때마다 '알 수없는 명령'이 출력됩니다.
'parseInputLoop'은 어떤 문자열에서도 읽히지 않으므로 문자열 비교를하지 않습니다. 전체 코드가 지나치게 복잡해 보입니다. 입력 된 문자를 버퍼에 저장 한 다음'repe cmpsb '를 사용하여 버퍼 내용을 일부 문자열과 비교하십시오. – Michael