home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / library / asm_kit / search.asm < prev    next >
Assembly Source File  |  1985-06-21  |  6KB  |  151 lines

  1. ;SEARCH--Searches one string for another
  2. ;  User tyes in keyword, then sentence
  3. ;  Program decides is sentence contains word
  4. ;  Prints out conclusion
  5. ;
  6. print_m       equ  9h              ;print string function
  7. buff_in       equ  0ah             ;buffered kbd input function
  8. doscall       equ  21h             ;DOS interrupt number
  9. ;
  10. ;***************************************************************
  11. st_seg       segment               ;define stack segment
  12.              db    20 dup    ('stack   ')
  13. st_seg       ends
  14. ;***************************************************************
  15. datarea      segment               ;define data area
  16. ;
  17. ;buffer to hold sentence
  18. sen_max      db    127d            ;max chars in sentence
  19. sen_real     db    ?               ;actual char in sentence
  20. sentence     db    127d dup (?)    ;space for 127 chars
  21. ;buffer to hold keyword
  22. key_max      db    20d             ;max chars in keyword
  23. key_real     db    ?               ;actual chars in keywd
  24. keyword      db    20d dup (?)     ;space for 20 chars
  25. mess1        db    0dh,0ah,'Enter Keyword: $'
  26. mess2        db    0dh,0ah,'Enter Sentence: $'
  27. mess3        db    0dh,0ah,'No Match.$'
  28. mess4        db    0dh,0ah,'Match!!!$'
  29. datarea      ends
  30. ;***************************************************************
  31. prognam      segment               ;define code segment
  32. ;---------------------------------------------------------------
  33. main         proc  far             ;main part of program
  34. ;
  35.              assume cs:prognam,ds:datarea
  36.              assume es:datarea
  37. ;
  38. start:                             ;starting execution address
  39. ;set up stack for return
  40.              push  ds              ;save old data segment
  41.              sub ax,ax             ;put zero in AX
  42.              push  ax              ;save it on stack
  43. ;
  44. ;set DS register to current data segment
  45.              mov  ax,datarea       ;datarea segment address
  46.              mov  ds,ax            ;into DS register
  47. ;
  48. ;set ES register to current extra segment
  49.              mov  ax,datarea       ;datarea segment address
  50.              mov  es,ax            ;into ES register
  51. ;
  52. ;GET KEYWORD AND PUT IN BUFFER
  53. new_key:
  54. ;
  55. ;print"enter keyword" message
  56.              mov  dx,offset mess1  ;addr in DX
  57.              mov  ah,print_m       ;print string function
  58.              int  doscall          ;call DOS
  59. ;
  60. ;get keyword and put in buffer
  61.              mov  dx,offset key_max ;addr of buffer
  62.              mov  ah,buff_in       ;buffered kbd input
  63.              int  doscall          ;call DOS
  64. ;
  65. ;GET SENTENCE AND PUT IN BUFFER
  66. new_sent:
  67. ;
  68. ;print"enter sentence" message
  69.              mov  dx,offset mess2  ;addr in DX
  70.              mov  ah,print_m       ;print string function
  71.              int  doscall          ;call DOS
  72. ;
  73. ;get sentence and put in buffer
  74.              mov  dx,offset sen_max ;addr of buffer
  75.              mov  ah,buff_in       ;buffered kbd input
  76.              int  doscall          ;call DOS
  77. ;
  78. ;SEARCH FOR KEYWORD IN SENTENCE
  79. ;
  80. ;SI register holds pointer to keyword
  81. ;DI register holds pointer to sentence
  82. ;BX register holds pointer to current starting place in sentence
  83. ;DX register holds count of character in sentence
  84. ;            less chars in keyword + 1
  85. ;CX register holds count of chars in word
  86. ;
  87.              cld                   ;set direction flag forward
  88.              ;
  89. ;
  90. ;claculate length of sentence less length of keyword, put in DX
  91.              mov  al,sen_real      ;length of sentence
  92.              sub  al,key_real      ;less length of word
  93.              jl   no_match         ;word longer than sentence
  94.              cbw                   ;change byte to word
  95.              mov  dx,ax            ;put in DX
  96.              inc  dx               ; + 1
  97. ;
  98. ;set BX to first character in sentence
  99.              mov  bx,offset sentence
  100. ;
  101. compare:
  102. ;
  103. ;set DI to BX--this is place in sentence
  104. ;  where comparision will begin
  105.              mov  di,bx
  106. ;
  107. ;set SI to start of keyword
  108.              mov si,offset keyword
  109. ;
  110. ;set CX to number of characters in keyword
  111.              mov  al,key_real      ;get count
  112.              cbw                   ;change byte to word
  113.              mov  cx,ax            ;put in CX
  114. ;
  115. ;compare keyword to this part of sentence
  116.              repe cmpsb            ;compare characters
  117.                                    ;repeat until CX = 0
  118.                                    ;or nomatch is found
  119.              jz   match            ;match found
  120. ;
  121. ;no match found here.  Advance BX to next
  122. ;  character in sentence, check if done
  123.              inc  bx                ;advance pointer
  124.              dec  dx                ;done?
  125.              jz   no_match          ;yes, no match
  126.              jmp  compare           ;no, try again
  127. ;
  128. ;print "match" message
  129. match:
  130.              mov  dx,offset mess4   ;addr in DX
  131.              mov  ah,print_m        ;print string function
  132.              int  doscall           ;call DOS
  133.              jmp  new_sent         ;get another sentence
  134. ;
  135. ;print "no match" message
  136. no_match:
  137.              mov  dx,offset mess3   ;addr in DX
  138.              mov  ah,print_m        ;print string function
  139.              int  doscall           ;call DOS
  140.              jmp  new_sent          ;get another sentence
  141. ;
  142.              ret                    ;return to DOS
  143. ;
  144. main         endp                   ;end of main part of program
  145. ;---------------------------------------------------------------
  146. prognam      ends                   ;end of code segment
  147. ;***************************************************************
  148. ;
  149.              end  start             ;end of assembly
  150. ;===============================================================
  151.