Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .model small
- .stack 100h
- .data
- msg db "input string to sort", 0dh, 0ah, '$'
- str db 50d, 50 dup('$')
- bip db 7, '$'
- endl db 0Dh, 0Ah, '$'
- .code
- sort macro
- ;for (int i = 0;i< len - 1; i++)
- ; for(int j = len - 1; j > i; j--)
- ; if (str[j] < str[j - 1])
- ; {
- ; swap(str[i], str[j]);
- ; }
- xor cx, cx
- mov bx, offset str ; bx = 0
- mov si, bx ; si = 0
- mov cl, [bx+1]
- dec cl
- add bx, cx ; bx = strlen
- loop_in_i:
- loop_in_j:
- mov ah, [bx + 2] ; str[j]
- mov al, [bx + 1] ; str[j-1]
- cmp al, ah ; if str[j] == str[j-1]
- jle dont_swap
- mov [bx + 1], ah ; swap
- mov [bx + 2], al
- dont_swap:
- dec bx ; j --
- cmp bx, si ; j > i
- jne loop_in_j
- inc si ; si ++
- mov bx, offset str
- add bl, [bx + 1]
- dec bx ; bx = strlen - 1
- cmp si, bx ; si < strlen - 1
- jl loop_in_i
- end:
- endm
- main:
- mov ax, @data
- mov ds, ax
- mov ah, 9
- lea dx, msg
- int 21h
- mov ah, 0Ah ; input string
- lea dx, str
- int 21h
- ;strlen str
- sort
- mov ah, 09h ;new line
- lea dx, endl
- int 21h
- mov dx, offset str + 2 ;output input string
- int 21h
- lea dx, bip ;sound
- int 21h
- mov ah, 04CH
- int 21h
- end main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement