Advertisement
rnort

Untitled

Mar 23rd, 2012
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. data segment
  2.     str db 100,?,100 dup (?)
  3.     msg1 db 13,10,"Enter string:$"
  4.     msg2 db 13,10,"Number founded!$"
  5.     msg3 db 13,10,"Number not founded!$"
  6. ends
  7. stack segment
  8.     db 200 dup(0)
  9. ends  
  10. code segment
  11.  
  12. new_word proc near
  13.  
  14.     ; bx - current pos
  15.  
  16. loop_1:
  17.     cmp str[bx],' '
  18.     je space  
  19.    
  20.     cmp bx, 2
  21.     je chk_n
  22.     cmp str[bx-1], ' '
  23.     jne continue
  24.    
  25. chk_n: 
  26.     cmp str[bx], '0'
  27.     jl continue
  28.     cmp str[bx], '9'
  29.     jg continue        
  30.     ret    
  31. space:
  32.    cmp str[bx+1], '0'
  33.    jl continue
  34.    cmp str[bx+1], '9'
  35.    jg continue
  36.    inc bx       ; /?
  37.    ret  
  38.        
  39. continue:
  40.     inc bx
  41.     cmp str[bx], "$"
  42.     jne loop_1
  43. nw_end:
  44.     ret
  45.  
  46. new_word endp
  47.  
  48. check_word proc near
  49.     mov cx,0
  50.     mov si,bx
  51. loop_2:
  52.     inc si  
  53.     cmp str[si], '0'
  54.         jl fail
  55.     cmp str[si], '9'
  56.         jg fail
  57.      cmp str[si], ' '
  58.      je loop_2_end
  59.      cmp str[si],'$'
  60.      jne loop_2
  61. ret
  62. fail:
  63.     cmp str[si], ' '
  64.     je loop_2_end
  65.     cmp str[si], '$'
  66.     je loop_2_end
  67.     mov cx,1
  68. loop_2_end:
  69.  
  70. ret
  71. check_word endp
  72.  
  73.  
  74. shuffle proc near
  75.  
  76. loop_main:
  77.    
  78.     mov si, bx
  79.    
  80. loop_main_child:
  81.     mov al, str[si+1]
  82.     mov str[si], al
  83.     inc si
  84.     cmp str[si], '$'
  85.     jne loop_main_child
  86.    
  87.     cmp str[bx], ' '
  88.     je loop_main_end
  89.     cmp str[bx],'$'
  90.     jne loop_main
  91.     ret
  92.  
  93. loop_main_end:
  94.  
  95.     ret
  96. shuffle endp
  97.  
  98. start:  
  99.    
  100.     mov ax, data
  101.     mov ds, ax
  102. ;enter string -------------------------------------    
  103.     mov dx, offset msg1
  104.     mov ah, 9
  105.     int 21h
  106.    
  107.     mov dx, offset str
  108.     mov ah, 0ah
  109.     int 21h
  110.    
  111.     xor dx, dx
  112.     mov dl, str[1]
  113.     add dx, 2                
  114.     mov bx, dx        ; ?
  115.     mov offset str[bx],'$'
  116. ;--------------------------------------------------
  117.     xor bx, bx
  118.     xor cx, cx  
  119.    
  120.     mov bx, 1
  121.     mov cx, 0  
  122.  
  123.     mov dx, offset str+2
  124.     mov bx, dx
  125. main:
  126.  
  127.     call new_word
  128.     cmp str[bx],'$'
  129.     je exit
  130.    
  131.     call check_word
  132.     cmp cx, 1
  133.     je main_end
  134.     call shuffle
  135. main_end:
  136.     inc bx
  137.     cmp str[bx], '$'
  138.         jne main
  139.    
  140.    
  141.  
  142.  
  143.    
  144. exit: ;-------------------------------------------      
  145.     mov dl, 0ah
  146.     mov ah, 2
  147.     int 21h
  148.    
  149.     mov dx, offset str+2
  150.     mov ah, 9
  151.     int 21h
  152.    
  153.     mov ah, 1
  154.     int 21h
  155.    
  156.     mov ax, 4c00h
  157.     int 21h
  158. ends
  159. end start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement