Okay, this is an annoying problem i'm making a command line operating system bootable from a floppy disk and the way i'm testing it atm is by inputting a command and outputting it.

The reason for this is that i want to know EXACTLY what its doing with the string and how it is being referenced etc so that i can compare it with a list of commands. The code function 'check' doesnt work at the moment and is very messy what with me playing around with it alot.

Code that would compare the inputted string with a command would be very helpful along with a thorough description OR a description of how i would go about it.

Currently the code is:

;boot code
;Load boot directive

;Set boot memory address
org 7c00h

push cs ;cs = ds
pop ds    
;print welcome
lea si,welcomeMessage
call print                  

;gets command
mov bh,0
 lea si,message
 call print
 mov dx,offset buffer
 mov ah,0ah         ;read string subroutine
 int 21h            ;get string
 call check
 jmp getCommand
;store 'magic' number at 0040h:0072h
; 0000h = cold reboot
; 1234h = warm reboot
mov ax, 0040h
mov ds,ax
mov w.[0072h],0000h
jmp 0FFFFh:0000h ;reboot!


print proc              ;arguments: string is in SI
  cmp b.[si],0           ;check for null termination
  jz stop
  mov al,[si]           ;get next char
  mov ah,0eh            ;teletype subroutine
  int 10h               ;print
  inc si                ;next lesson
  jmp nextChar          ;type next char
  ret                   ;return to caller
print endp                              

check proc              ;arguments: string must be in SI
  lea di,help

 xor bx,bx
 lea si,help
 mov bx,offset buffer - 1
 mov ah, 09
 inc bx
 mov dx,[bx]
 int 21h
 cmp dx,0
 jnz temp
check endp
lfcr equ 13,10,0           

welcomeMessage db "Welcome to MYCROS!"
db 13,10, "For a list of commands type 'help'"
db lfcr

message db 13,10, "Command: ",0

buffer db 50,50 dup " "

help db "help",0

Recommended Answers

All 10 Replies

Not sure what your question is....

A command line selector should be a table of ASCII commands with associated enumeration. When a string match is found, then use the enumeration with a jump table to call that command handler!

thanks wild goose so i assume that you mean some thing like (ignore syntax its pseudo code)
commandsArray(command1,command2,command3) etc
and then it would iincrement through each one to find the code?
i can compare one letter at a time but i'm not sure how i would go about checking it one letter at a time for a whole word :/ any ideas?

There's usually hundreds of commands in a scripting language so would mean more like...

iApple = 1
iPear = 2
iCorn =3
iDog = 4
iGrape= 5

xApple db  'Apple',0
xCorn   db  'Corn',0
xDog    db  'Dog',0
xGrape  db  'Grape',0
xPear    db   'Pear',0

Id     DWORD   ?
Name   DWORD ?

; Alpha sorted for speed
Label FoodTable
   Food < offset xApple, iApple >
   Food < offset xCorn, iCorn >
   Food < offset  xDog, iDog >
   Food < offset  xGrape, iGrape >
   Food < offset  xPear, iPear >

Being alpha sorted, the matching command record can be found quicker.
Then use the eumerationId for a code vector table.

commented: amazing +1

So you mean that by creating the commands as you said and asigning them id's i can effectively do this:

create all commands following a set structure
go to first id
compare input to the first id's string
if not equal increment the id and try again and so on
if they are equal jump to the corresponding code block and execute code

sound about right? if it is then i get what you mean otherwise i've somewhat missed the point


That's your initial get the code working step.
Then, once it works, since the text is alpha sorted, and the records are fixed size, do a binary search.

Look a record COUNT/2, Is it, above or below, Divide in 1/2 try again.

So essentially very fast command search since they're alpha sorted.

oh wow i think i get it now i'll start work on it as soon as i can thanks so much :D

sorry i'm a noob and dont know how to edit >.< but emu 8086 does not support a struct it won't compile and gets confused an alternative command perhaps?

Not familiar with EMU8086 and assuming you can't use an alternate tool you can do it this way!

; Alpha sorted for speed
Label FoodTable
    DWORD offset xApple, iApple
    DWORD offset xCorn, iCorn
    DWORD offset  xDog, iDog
    DWORD offset  xGrape, iGrape
    DWORD offset  xPear, iPear

Taking advantage of the scalar *8; {*2, *4, *8 } and that each record is 8 bytes in length!

; ebx is index 0...Count-1
    mov eax,FoodTable[ ebx*8 ]  ; Get a 32-bit String offsets 
    mov eax,FoodTable[ ebx*8 + 4 ]   ; Get a 32-bit String Id

NOTE: In that STRUCT I just realized I had the name and string Id's names swapped accidently. It should have been Name for the string offset and Id for the command enumeration that you would use in the function lookup! There are actually many ways you can do this table to function lookup.

thank youuuuuuuuuuuu.... again :D i'll apply it when i next work on it (tomorrow) :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.