Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. .model small
  2. .stack 100h
  3. .data
  4. msg db "input string to sort", 0dh, 0ah, '$'
  5. str db 50d, 50 dup('$')
  6. bip db 7, '$'
  7. endl db 0Dh, 0Ah, '$'
  8. .code
  9.  
  10. sort macro
  11. ;for (int i = 0;i< len - 1; i++)
  12. ; for(int j = len - 1; j > i; j--)
  13. ; if (str[j] < str[j - 1])
  14. ; {
  15. ; swap(str[i], str[j]);
  16. ; }
  17.  
  18. xor cx, cx
  19. mov bx, offset str ; bx = 0
  20. mov si, bx ; si = 0
  21.  
  22. mov cl, [bx+1]
  23. dec cl
  24. add bx, cx ; bx = strlen
  25. loop_in_i:
  26. loop_in_j:
  27. mov ah, [bx + 2] ; str[j]
  28. mov al, [bx + 1] ; str[j-1]
  29. cmp al, ah ; if str[j] == str[j-1]
  30. jle dont_swap
  31. mov [bx + 1], ah ; swap
  32. mov [bx + 2], al
  33. dont_swap:
  34. dec bx ; j --
  35. cmp bx, si ; j > i
  36. jne loop_in_j
  37. inc si ; si ++
  38. mov bx, offset str
  39. add bl, [bx + 1]
  40. dec bx ; bx = strlen - 1
  41. cmp si, bx ; si < strlen - 1
  42. jl loop_in_i
  43.  
  44. end:
  45.  
  46. endm
  47.  
  48. main:
  49. mov ax, @data
  50. mov ds, ax
  51.  
  52. mov ah, 9
  53. lea dx, msg
  54. int 21h
  55.  
  56. mov ah, 0Ah ; input string
  57. lea dx, str
  58. int 21h
  59.  
  60. ;strlen str
  61. sort
  62.  
  63. mov ah, 09h ;new line
  64. lea dx, endl
  65. int 21h
  66.  
  67. mov dx, offset str + 2 ;output input string
  68. int 21h
  69.  
  70. lea dx, bip ;sound
  71. int 21h
  72.  
  73. mov ah, 04CH
  74. int 21h
  75. end main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement