Issue
how do i compare the string in the buffer with a command like '--help'
how would you compare the freshly inputted text in the buffer with a command here is my code
xor ax, ax
mov ds, ax
mov es, ax
cld
;bg
MOV AH, 06h
XOR AL, AL
XOR CX, CX
MOV DX, 184FH
MOV BH, 1Eh
INT 10H
;cursor
mov dh, 1
mov dl, 30
mov bh, 0
mov ah, 2
int 10h
;text
mov si, msg
mov bh, 0
lodsb
More:
mov ah, 0Eh ; BIOS.Teletype
int 10h
lodsb
cmp al, 0
jnz More
;cursor
mov dh, 3
mov dl, 2
mov bh, 0
mov ah, 2
int 10h
;commandline
Key:
mov di, buf
Next:
mov ah, 00h ;GetKeyboardKey
int 16h
stosb
mov bh, 0
mov ah, 0Eh ; BIOS.Teletype
int 10h
cmp al, 13
jne Next
mov al, 10
int 10h
buf db '........'
help db '--help'
msg db 'WELCOME TO DARSHOS', 0
times 510-($-$$) db 0
dw 0xAA55```
Solution
help db '--help'
It's not clear why you have prefixed this command with those '--'.
For a practical approach to the task, consider next list of available commands:
list db 'cls', 13
db 'help', 13
db 'date', 13
db 13
Below is one method of searching through this list of CarriageReturn-terminated ASCII strings where no string has more than 7 text characters plus a terminating byte (13). That's 8 in total since that was the limit we chose on inputting the command that we're trying to locate.
The snippet uses a couple of string instructions:
- The
lodsbstring instruction loads the byte atDS:SIinto theALregister. This will automatically advance the pointer. If the direction flagDFis clear it will increment by one. - The
scasbstring instruction will compare theALregister with the byte atES:DI. This will modify flags that we can interrogate and it will also automatically advance the pointer.
cld
mov si, list
NextItemOnList:
mov di, buf ; Contains the command we want to find (terminated by 13)
NextChar:
lodsb
scasb
jne NotThisOne
cmp al, 13
jne NextChar
Found:
...
NotThisOne:
dec si ; Back to where the mismatch occured
SkipRemainder:
lodsb ; Skip remainder of this list item
cmp al, 13
jne SkipRemainder
cmp byte [si], 13 ; EndOfList ?
jne NextItemOnList ; No
NotFound:
...
With the above code we can find out if the command is on the list, but which was it?
- We can choose to associate an index with each command on the list, like in:
cld
xor cx, cx ; cls=0, help=1, date=2
mov si, list
NextItemOnList:
mov di, buf ; Contains the command we want to find (terminated by 13)
NextChar:
lodsb
scasb
jne NotThisOne
cmp al, 13
jne NextChar
Found:
...
NotThisOne:
dec si ; Back to where the mismatch occured
SkipRemainder:
lodsb ; Skip remainder of this list item
cmp al, 13
jne SkipRemainder
inc cx ; Next index
cmp byte [si], 13 ; EndOfList ?
jne NextItemOnList ; No
NotFound:
...
- Or we can add to the list the actual addresses where the commands are going to get processed, like in:
list dw xCls
db 'cls', 13
dw xHelp
db 'help', 13
dw xDate
db 'date', 13
dw xFail
...
cld
mov si, list
NextItemOnList:
lodsw ; Address of command's execution
mov bx, ax
mov di, buf ; Contains the command we want to find (terminated by 13)
NextChar:
lodsb
scasb
jne NotThisOne
cmp al, 13
jne NextChar
Found:
...
NotThisOne:
dec si ; Back to where the mismatch occured
SkipRemainder:
lodsb ; Skip remainder of this list item
cmp al, 13
jne SkipRemainder
cmp word [si], xFail ; EndOfList ?
jne NextItemOnList ; No
NotFound:
...
Answered By - Sep Roland
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.