Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;;permutation of strings using heap's algorithm
- org 100h
- .data
- intro db "Permutation of string using Heap's Algorithm$"
- string db "abcde$"
- strLen = ($ - string) - 1
- c dw strLen dup(0)
- newLine db 0ah, 0dh, "$"
- i dw 0
- .code
- mov dx, offset intro
- mov ah, 09h
- int 21h
- mov dx, offset newLine
- int 21h
- mov dx, offset newLine
- int 21h
- mov dx, offset string
- int 21h
- mov dx, offset newLine
- int 21h
- while:
- mov bx, i
- cmp bx, strLen
- jnl endWhl
- push bx
- add bx, bx
- mov cx, c[bx]
- pop bx
- cmp cx, i
- jnl else
- mov ax, i
- mov dx, 0
- mov si, 2
- div si
- cmp dx, 0
- jne notEven
- push ax
- mov ah, string[0]
- xchg ah, string[bx]
- xchg ah, string[0]
- pop ax
- jmp endNotZero
- notEven:
- push ax
- push bx
- add bx, bx
- mov di, c[bx]
- pop bx
- mov ah, string[di]
- xchg ah, string[bx]
- xchg ah, string[di]
- pop ax
- endNotZero:
- mov dx, offset string
- mov ah, 09h
- int 21h
- mov dx, offset newLine
- int 21h
- push bx
- add bx, bx
- inc c[bx]
- pop bx
- mov i, 0
- jmp while
- else:
- push bx
- add bx, bx
- mov c[bx],0
- pop bx
- inc i
- jmp while
- endWhl:
- hlt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement