EMU8086 OS Command Comparison

Please support our Assembly advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2009
Posts: 8
Reputation: jhouns is an unknown quantity at this point 
Solved Threads: 0
jhouns jhouns is offline Offline
Newbie Poster

EMU8086 OS Command Comparison

 
0
  #1
Oct 18th, 2009
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:
  1. ;boot code
  2. ;==========================================
  3. ;Load boot directive
  4. #MAKE_BOOT#
  5.  
  6. ;Set boot memory address
  7. org 7c00h
  8.  
  9. push cs ;cs = ds
  10. pop ds
  11. ;==========================================
  12. ;print welcome
  13. ;==========================================
  14.  
  15. begin:
  16. lea si,welcomeMessage
  17. call print
  18.  
  19. ;==========================================
  20. ;gets command
  21. ;==========================================
  22. mov bh,0
  23. getCommand:
  24. lea si,message
  25. call print
  26. mov dx,offset buffer
  27. mov ah,0ah ;read string subroutine
  28. int 21h ;get string
  29. call check
  30. jmp getCommand
  31.  
  32. ;==========================================
  33. ;reboot
  34. ;==========================================
  35. ;store 'magic' number at 0040h:0072h
  36. ; 0000h = cold reboot
  37. ; 1234h = warm reboot
  38. mov ax, 0040h
  39. mov ds,ax
  40. mov w.[0072h],0000h
  41. jmp 0FFFFh:0000h ;reboot!
  42.  
  43. ;==========================================
  44. ;procedures
  45. ;==========================================
  46.  
  47. print proc ;arguments: string is in SI
  48. nextChar:
  49. cmp b.[si],0 ;check for null termination
  50. jz stop
  51.  
  52. mov al,[si] ;get next char
  53. mov ah,0eh ;teletype subroutine
  54. int 10h ;print
  55. inc si ;next lesson
  56. jmp nextChar ;type next char
  57.  
  58. stop:
  59. ret ;return to caller
  60. print endp
  61.  
  62. check proc ;arguments: string must be in SI
  63. getNo:
  64. lea di,help
  65.  
  66. checkCom:
  67. xor bx,bx
  68. lea si,help
  69. mov bx,offset buffer - 1
  70. mov ah, 09
  71. temp:
  72. inc bx
  73. mov dx,[bx]
  74. int 21h
  75. cmp dx,0
  76. jnz temp
  77. ret
  78. check endp
  79. ;==========================================
  80. ;vars
  81. ;==========================================
  82. lfcr equ 13,10,0
  83.  
  84. welcomeMessage db "Welcome to MYCROS!"
  85. db 13,10, "For a list of commands type 'help'"
  86. db lfcr
  87.  
  88. message db 13,10, "Command: ",0
  89.  
  90. buffer db 50,50 dup " "
  91.  
  92. help db "help",0
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 395
Reputation: gerard4143 is on a distinguished road 
Solved Threads: 47
gerard4143's Avatar
gerard4143 gerard4143 is offline Offline
Posting Whiz
 
0
  #2
Oct 18th, 2009
Not sure what your question is....
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark
 
0
  #3
Oct 19th, 2009
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!
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 8
Reputation: jhouns is an unknown quantity at this point 
Solved Threads: 0
jhouns jhouns is offline Offline
Newbie Poster
 
0
  #4
Oct 19th, 2009
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?
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark
 
1
  #5
Oct 19th, 2009
There's usually hundreds of commands in a scripting language so would mean more like...
  1. iApple = 1
  2. iPear = 2
  3. iCorn =3
  4. iDog = 4
  5. iGrape= 5
  6.  
  7. xApple db 'Apple',0
  8. xCorn db 'Corn',0
  9. xDog db 'Dog',0
  10. xGrape db 'Grape',0
  11. xPear db 'Pear',0
  12.  
  13. Food STRUCT
  14. Id DWORD ?
  15. Name DWORD ?
  16. ENDS
  17.  
  18.  
  19. ; Alpha sorted for speed
  20. Label FoodTable
  21. Food < offset xApple, iApple >
  22. Food < offset xCorn, iCorn >
  23. Food < offset xDog, iDog >
  24. Food < offset xGrape, iGrape >
  25. Food < offset xPear, iPear >
  26. LabelFoodTableEnd

Being alpha sorted, the matching command record can be found quicker.
Then use the eumerationId for a code vector table.
Last edited by wildgoose; Oct 19th, 2009 at 2:43 pm.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 8
Reputation: jhouns is an unknown quantity at this point 
Solved Threads: 0
jhouns jhouns is offline Offline
Newbie Poster
 
0
  #6
Oct 19th, 2009
So you mean that by creating the commands as you said and asigning them id's i can effectively do this:

  1. PSEUDO CODE =]
  2. create all commands following a set structure
  3. go to first id
  4. compare input to the first id's string
  5. if not equal increment the id and try again and so on
  6. if they are equal jump to the corresponding code block and execute code
  7.  

sound about right? if it is then i get what you mean otherwise i've somewhat missed the point
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark
 
1
  #7
Oct 19th, 2009
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.
Last edited by wildgoose; Oct 19th, 2009 at 6:25 pm.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 8
Reputation: jhouns is an unknown quantity at this point 
Solved Threads: 0
jhouns jhouns is offline Offline
Newbie Poster
 
0
  #8
Oct 20th, 2009
oh wow i think i get it now i'll start work on it as soon as i can thanks so much
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 8
Reputation: jhouns is an unknown quantity at this point 
Solved Threads: 0
jhouns jhouns is offline Offline
Newbie Poster
 
0
  #9
Oct 20th, 2009
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?
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark
 
0
  #10
Oct 20th, 2009
Not familiar with EMU8086 and assuming you can't use an alternate tool you can do it this way!
  1. ; Alpha sorted for speed
  2. Label FoodTable
  3. DWORD offset xApple, iApple
  4. DWORD offset xCorn, iCorn
  5. DWORD offset xDog, iDog
  6. DWORD offset xGrape, iGrape
  7. DWORD offset xPear, iPear
Taking advantage of the scalar *8; {*2, *4, *8 } and that each record is 8 bytes in length!
  1. ; ebx is index 0...Count-1
  2. mov eax,FoodTable[ ebx*8 ] ; Get a 32-bit String offsets
  3. 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.
Last edited by wildgoose; Oct 20th, 2009 at 3:12 pm.
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the Assembly Forum
Thread Tools Search this Thread



Tag cloud for Assembly
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC