Advertisement
cf1709

stringPermHeap.asm

Oct 16th, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;;permutation of strings using heap's algorithm
  2.  
  3. org 100h
  4.  
  5. .data
  6. intro db "Permutation of string using Heap's Algorithm$"
  7. string db "abcde$"
  8. strLen = ($ - string) - 1
  9. c dw strLen dup(0)
  10. newLine db 0ah, 0dh, "$"
  11. i dw 0
  12.  
  13. .code
  14. mov dx, offset intro
  15. mov ah, 09h
  16. int 21h
  17. mov dx, offset newLine
  18. int 21h
  19. mov dx, offset newLine
  20. int 21h
  21. mov dx, offset string
  22. int 21h
  23. mov dx, offset newLine
  24. int 21h
  25.  
  26. while:
  27. mov bx, i
  28. cmp bx, strLen
  29. jnl endWhl
  30.     push bx
  31.     add bx, bx
  32.     mov cx, c[bx]
  33.     pop bx
  34.     cmp cx, i
  35.     jnl else
  36.         mov ax, i
  37.         mov dx, 0
  38.         mov si, 2
  39.         div si
  40.        
  41.         cmp dx, 0
  42.         jne notEven
  43.             push ax
  44.             mov ah, string[0]
  45.             xchg ah, string[bx]
  46.             xchg ah, string[0]
  47.             pop ax
  48.             jmp endNotZero            
  49.         notEven:  
  50.             push ax
  51.             push bx
  52.             add bx, bx
  53.             mov di, c[bx]
  54.             pop bx            
  55.             mov ah, string[di]
  56.             xchg ah, string[bx]
  57.             xchg ah, string[di]            
  58.             pop ax
  59.         endNotZero:      
  60.             mov dx, offset string
  61.             mov ah, 09h
  62.             int 21h
  63.             mov dx, offset newLine
  64.             int 21h
  65.             push bx
  66.             add bx, bx                        
  67.             inc c[bx]
  68.             pop bx
  69.             mov i, 0
  70.         jmp while
  71.     else:
  72.         push bx
  73.         add bx, bx
  74.         mov c[bx],0
  75.         pop bx
  76.         inc i
  77.         jmp while
  78. endWhl:
  79.  
  80. hlt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement