944,137 Members | Top Members by Rank

Ad:
  • Assembly Discussion Thread
  • Unsolved
  • Views: 2339
  • Assembly RSS
You are currently viewing page 1 of this multi-page discussion thread
Oct 18th, 2009
0

EMU8086 OS Command Comparison

Expand Post »
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:
Assembly Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jhouns is offline Offline
8 posts
since Sep 2009
Oct 18th, 2009
0
Re: EMU8086 OS Command Comparison
Not sure what your question is....
Reputation Points: 499
Solved Threads: 367
Postaholic
gerard4143 is offline Offline
2,198 posts
since Jan 2008
Oct 19th, 2009
0
Re: EMU8086 OS Command Comparison
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!
Reputation Points: 546
Solved Threads: 99
Practically a Posting Shark
wildgoose is offline Offline
891 posts
since Jun 2009
Oct 19th, 2009
0
Re: EMU8086 OS Command Comparison
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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jhouns is offline Offline
8 posts
since Sep 2009
Oct 19th, 2009
1
Re: EMU8086 OS Command Comparison
There's usually hundreds of commands in a scripting language so would mean more like...
Assembly Syntax (Toggle Plain Text)
  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.
Reputation Points: 546
Solved Threads: 99
Practically a Posting Shark
wildgoose is offline Offline
891 posts
since Jun 2009
Oct 19th, 2009
0
Re: EMU8086 OS Command Comparison
So you mean that by creating the commands as you said and asigning them id's i can effectively do this:

Assembly Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jhouns is offline Offline
8 posts
since Sep 2009
Oct 19th, 2009
1
Re: EMU8086 OS Command Comparison
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.
Reputation Points: 546
Solved Threads: 99
Practically a Posting Shark
wildgoose is offline Offline
891 posts
since Jun 2009
Oct 20th, 2009
0
Re: EMU8086 OS Command Comparison
oh wow i think i get it now i'll start work on it as soon as i can thanks so much
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jhouns is offline Offline
8 posts
since Sep 2009
Oct 20th, 2009
0
Re: EMU8086 OS Command Comparison
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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jhouns is offline Offline
8 posts
since Sep 2009
Oct 20th, 2009
0
Re: EMU8086 OS Command Comparison
Not familiar with EMU8086 and assuming you can't use an alternate tool you can do it this way!
Asm Syntax (Toggle Plain Text)
  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!
Asm Syntax (Toggle Plain Text)
  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.
Reputation Points: 546
Solved Threads: 99
Practically a Posting Shark
wildgoose is offline Offline
891 posts
since Jun 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Assembly Forum Timeline: Question about arrays
Next Thread in Assembly Forum Timeline: convert number to ascii in mips?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC