Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- data segment
- str db 100,?,100 dup (?)
- msg1 db 13,10,"Enter string:$"
- msg2 db 13,10,"Number founded!$"
- msg3 db 13,10,"Number not founded!$"
- ends
- stack segment
- db 200 dup(0)
- ends
- code segment
- new_word proc near
- ; bx - current pos
- loop_1:
- cmp str[bx],' '
- je space
- cmp bx, 2
- je chk_n
- cmp str[bx-1], ' '
- jne continue
- chk_n:
- cmp str[bx], '0'
- jl continue
- cmp str[bx], '9'
- jg continue
- ret
- space:
- cmp str[bx+1], '0'
- jl continue
- cmp str[bx+1], '9'
- jg continue
- inc bx ; /?
- ret
- continue:
- inc bx
- cmp str[bx], "$"
- jne loop_1
- nw_end:
- ret
- new_word endp
- check_word proc near
- mov cx,0
- mov si,bx
- loop_2:
- inc si
- cmp str[si], '0'
- jl fail
- cmp str[si], '9'
- jg fail
- cmp str[si], ' '
- je loop_2_end
- cmp str[si],'$'
- jne loop_2
- ret
- fail:
- cmp str[si], ' '
- je loop_2_end
- cmp str[si], '$'
- je loop_2_end
- mov cx,1
- loop_2_end:
- ret
- check_word endp
- shuffle proc near
- loop_main:
- mov si, bx
- loop_main_child:
- mov al, str[si+1]
- mov str[si], al
- inc si
- cmp str[si], '$'
- jne loop_main_child
- cmp str[bx], ' '
- je loop_main_end
- cmp str[bx],'$'
- jne loop_main
- ret
- loop_main_end:
- ret
- shuffle endp
- start:
- mov ax, data
- mov ds, ax
- ;enter string -------------------------------------
- mov dx, offset msg1
- mov ah, 9
- int 21h
- mov dx, offset str
- mov ah, 0ah
- int 21h
- xor dx, dx
- mov dl, str[1]
- add dx, 2
- mov bx, dx ; ?
- mov offset str[bx],'$'
- ;--------------------------------------------------
- xor bx, bx
- xor cx, cx
- mov bx, 1
- mov cx, 0
- mov dx, offset str+2
- mov bx, dx
- main:
- call new_word
- cmp str[bx],'$'
- je exit
- call check_word
- cmp cx, 1
- je main_end
- call shuffle
- main_end:
- inc bx
- cmp str[bx], '$'
- jne main
- exit: ;-------------------------------------------
- mov dl, 0ah
- mov ah, 2
- int 21h
- mov dx, offset str+2
- mov ah, 9
- int 21h
- mov ah, 1
- int 21h
- mov ax, 4c00h
- int 21h
- ends
- end start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement