daily pastebin goal
36%
SHARE
TWEET

Bubble Sort

rohits134 Dec 31st, 2012 1,231 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .model small
  2. .data
  3.  msg db 10,13,"Enter 5 numbers: $"
  4.  arr1 db 5 dup(0)
  5.  msg1 db 10,13,"Enter a number: $"
  6.  newline db 10,13,"$"
  7.  count db 5
  8.  i db 5
  9.  j db 4
  10.  print macro str
  11.     lea dx,str
  12.     mov ah,09h
  13.     int 21h  
  14.  endm
  15.  
  16. .code
  17.  mov ax,@data
  18.  mov ds,ax
  19.  
  20.  print msg
  21.  lea si,arr1
  22.  
  23.  x:        
  24.  print msg1
  25.  call accept
  26.  mov [si],bl
  27.  inc si
  28.  dec count
  29.  jnz x
  30.  dec si
  31.  mov cl,5
  32.  mov count,cl
  33.  xx:
  34.  call display
  35.  dec si
  36.  dec count
  37.  jnz xx      
  38.  
  39.  mov al,5
  40.  mov i,al
  41.  ex1:lea si,arr1
  42.  mov al,4
  43.  mov j,al
  44.  ex:call comparenexchange
  45.  inc si
  46.  dec j
  47.  jnz ex
  48.  dec i
  49.  jnz ex1
  50.  mov ah,4ch
  51.  int 21h
  52.  
  53.  proc accept near:
  54.     mov ah,01h
  55.     int 21h
  56.     mov cl,4
  57.     shl al,cl
  58.     mov bl,al
  59.     mov ah,01h
  60.     int 21h
  61.     cmp al,39h
  62.     jbe s
  63.     sub al,7h
  64.     s:
  65.     sub al,30h
  66.     add bl,al
  67.     ret
  68.  
  69.  proc display near:
  70.     print newline
  71.     mov al,[si]
  72.     and al,0f0h
  73.     mov cl,4
  74.     shr al,cl
  75.     mov dl,al
  76.     add dl,30h
  77.     cmp dl,39h
  78.     jle xxx:
  79.     add dl,7h
  80.     xxx:
  81.     mov ah,02h
  82.     int 21h
  83.     mov al,[si]
  84.     and al,0fh
  85.     mov dl,al
  86.     add dl,30h
  87.     cmp dl,39h
  88.     jle xxxx:
  89.     add dl,7h
  90.     xxxx:
  91.     mov ah,02h
  92.     int 21h
  93.     ret                  
  94.  
  95.  proc comparenexchange near:
  96.     mov al,[si]
  97.     inc si
  98.     mov bl,[si]
  99.     cmp al,bl
  100.     jbe exchange:
  101.     call xchange
  102.     exchange:
  103.     dec si
  104.     ret
  105.        
  106.  proc xchange near:
  107.     dec si
  108.     mov al,[si]
  109.     inc si
  110.     mov bl,[si]
  111.     mov [si],al
  112.     dec si
  113.     mov [si],bl
  114.     inc si
  115.     ret
RAW Paste Data
Top