Question

I've looked at How to compare two strings assembly and I'm am trying to compare character by character until a character doesn't match and I can't seem to get my code to function how I want it to.

I'm making a simple shell and I'm starting with the help command:

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

It reads the string entered by the user off the stack. Here is the user input code:

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

It uses BIOS interrupts to achieve input and output.

It outputs 'Unknown command' each time despite entering 'help'.

Était-ce utile?

La solution

mov bh, [bx]
mov bl, s_HELP_COMMAND

The first line loads a byte from... whatever bp pointed to. I suppose it's an entered character(?). The second line loads the low byte of the address (offset part of the address) of s_HELP_COMMAND. This does not seem useful.

Perhaps you intended mov bl, [s_HELP_COMMAND]. This would give you the character 'h'. Incrementing it is going to give you 'g', not the next character in the command ('e').

There may be a further complication. [bp] defaults to [ss:bp]. [bx] defaults to [ds:bx] Unless ss = ds (could be true - you don't show that part) these are not going to refer to the same place in memory.

I suggest you re-think your entire parseInput routine (and perhaps previous routines). Take smaller steps!

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top