Not sure what your question is....
gerard4143
Nearly a Posting Maven
2,272 posts since Jan 2008
Reputation Points: 512
Solved Threads: 387
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!
wildgoose
Practically a Posting Shark
896 posts since Jun 2009
Reputation Points: 546
Solved Threads: 99
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
Food STRUCT
Id DWORD ?
Name DWORD ?
ENDS
; 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 >
LabelFoodTableEnd
Being alpha sorted, the matching command record can be found quicker.
Then use the eumerationId for a code vector table.
wildgoose
Practically a Posting Shark
896 posts since Jun 2009
Reputation Points: 546
Solved Threads: 99
Almost.
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.
wildgoose
Practically a Posting Shark
896 posts since Jun 2009
Reputation Points: 546
Solved Threads: 99
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.
wildgoose
Practically a Posting Shark
896 posts since Jun 2009
Reputation Points: 546
Solved Threads: 99