Results 1 to 4 of 4

Thread: Bubble Sort in TASM

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2010
    Location
    Poland
    Posts
    112
    Thanks
    8
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Bubble Sort in TASM

    recently I've started to learning assembler (using TASM syntax), my first task was to made bubble sort...
    I made an implementation, I checked it in Turbo Debugger and elements are in fact replaced if the appropriate condition is met, elements are swapped

    but the program runs into infinite loop and I can not notice why is that
    here is the entire code
    Qt Code:
    1. ;program do metody babelkowej
    2.  
    3. .MODEL SMALL
    4. ; Algorytm sortowania babelkowego:
    5. ; 1. Start.
    6. ; 2. index = 0; zamiany = 0;
    7. ; 3. Odczytaj dwa sasiadujace elementy z tablicy o pozycjach index oraz
    8. ; index + 1; jezeli pierwszy z odczytanych elementow jest wiekszy od
    9. ; swojego nastepnika, to zamien elementy miejscami oraz zwieksz zamiany.
    10. ; 4. Zwieksz index o jeden.
    11. ; 5. Jezeli index < dlugosc_tablicy - 2 to skacz do 3.
    12. ; 6. Skacz do 2 jezeli zamiany rozne od zera.
    13. ; 7. Stop.
    14. .DATA
    15.  
    16. t DB 01h, 02h, 00h, 10h, 12h, 33h, 15h, 09h, 11h, 08h, 0Ah, 00h
    17. ; 1, 2, 0, 16, 18, 51, 21, 9, 17, 8, 10, 0 ;po sorcie2=> 00h,00h,01h,02h,08h,09h,0Ah,10h,11h,12h,15h,33h
    18. t_size EQU 11 ; t_lenght
    19. again_s db 0 ; if again_s == 1, swap was made, again
    20. .CODE
    21. s:
    22. mov ax,@DATA
    23. mov ds,ax
    24. ;buble sort
    25. prepare:
    26. mov bx, OFFSET t ; load the t offset into bx
    27. again:
    28. mov again_s,0 ; XOR the flag
    29. xor si,si ; XOR used indexing register
    30. nextElement:
    31. mov ax,[bx+si] ; first compared element
    32. mov cx,[bx+si+1] ; second one
    33. cmp ax,cx ; comparing
    34. jbe noSwap ; if first <= next jmp no swap
    35. xchg ax,cx ; else swap
    36. mov again_s,1 ; set the flag
    37. noSwap:
    38. inc si ; increment index
    39. cmp si,t_size ; compare the index with t_size
    40. jb nextElement
    41. cmp again_s,1 ; if last element, check the flag
    42. je again
    43. koniec:
    44. mov ax,4c00h
    45. int 21h
    46. .STACK 100H
    47. end s
    To copy to clipboard, switch view to plain text mode 

    an important attention : I set t_size equal to 11, even though the real size equals 12. I made is so, because I tried to meet the condition when the index points at the last element (counting from 0)
    Last edited by kornicameister; 3rd March 2011 at 10:05. Reason: translation from polish code comments
    My schedule makes my cry
    My works makes my laugh
    My life makes... oh...no....

Similar Threads

  1. How to sort a Qlist AND get a sort key?
    By agerlach in forum Qt Programming
    Replies: 3
    Last Post: 26th July 2010, 18:44
  2. can't get right data after sort
    By wirasto in forum Qt Programming
    Replies: 5
    Last Post: 28th June 2009, 18:19
  3. QAbstractTableModel and sort
    By foxyproxy in forum Qt Programming
    Replies: 7
    Last Post: 25th March 2008, 09:30
  4. How to sort QMap
    By mamyte03@gmail.com in forum Qt Programming
    Replies: 2
    Last Post: 9th November 2007, 10:11
  5. When sort the lists?
    By SkripT in forum Qt Programming
    Replies: 6
    Last Post: 14th April 2006, 16:30

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.