;============================================================================== ;file :bubble2.asm ;author :Andre Long ;due :April 26, 2006 ;description :This program will fill an array with random numbers and then use ; the bubble sort algorithm to sort the numbers in order and will ; keep track of how many passeses, comparisons, and swaps are made ; The random process will use a file called randy3.asm ;============================================================================== ;procedures to INCLUDE Pcmac.inc EXTRN NEWLINE:FAR ;display a new line EXTRN GETDEC$:FAR ;gets 16 bit decimal value unsigned EXTRN PUTDEC$:FAR ;display 16 bit value unsigned EXTRN PUTSTRNG:FAR ;display charactor string EXTRN random:NEAR ;subprodecure EXTRN reseed:NEAR ;sunprocedure ;============================================================================== .MODEL SMALL .586 .STACK 100h .DATA PUBLIC seed PUBLIC randomNumber mess1 DB "Randomized Array ", 13, 10, '$' mess2 DB "Sorted Array But stoped processing array when sorted", 13, 10, '$' mess3 DB "Passes =", '$' mess4 DB "Comparisons =", '$' mess5 DB "Swaps =", '$' numRay DB 100 DUP (?) seed DW ? randomNumber DW ? counter DW 0 spaceBlank DB " ",'$' numCounter DW 0 i DB ? j DB ? n DB 100 nn DB ? temp DB ? countPass DW 0 countComp DW 0 countSwap DW 0 specSwap DW 0 ;============================================================================== .CODE bubble proc _Begin ;Macro for boiler plate mov bl, 1 mov ax, 5555h ;inital seed value for ressed call reseed ;call subprocedure mov si, 0 mov ax, 0 red: call random ;Load array with random numbers mov ax, randomNumber ;came from random mov [numRay + si], al inc si cmp si, 100 jb red jmp next1 next1: mov si, 0 ;display array sPutStr mess1 mov bh, 1 next2: mov al, [numRay + si] call putdec$ inc numCounter cmp numCounter, 12 jb next3 jmp LL LL: mov numCounter, 0 call newline jmp next3 next3: inc si cmp si, 100 jb next2 jmp brutForce brutForce: mov i, 0 mov ax, 0 mov bx, 0 mov al, n mov bl, 1 sub al, bl ;n-1 mov nn, al bf1: mov specSwap, 0 mov al, nn cmp i, al jbe innerL jmp doneOutter innerL: mov j, 0 mov al, nn hh: cmp j, al jb bf2 jmp doneInner bf2: mov dx, 0 mov cx, 0 mov cl, j mov di, cx bf3: mov dl, [numRay + di] cmp [numRay + di + 1], dl inc countComp inc j jb swap1a jmp hh swap1a: mov cx, 0 mov cl, [numRay + di] mov temp, cl mov cl, [numRay + di + 1] mov [numRay + di], cl mov cl, temp mov [numRay + di + 1], cl inc countSwap inc specSwap jmp hh doneInner: inc countPass inc i cmp specSwap, 0 je doneOutter jmp bf1 doneOutter: next4: mov ax, 0 mov si, 0 mov numCounter, 0 ;display array 2nd time call newline call newline sPutStr mess2 mov bh, 1 call newline call newline next5: mov al, [numRay + si] call putdec$ inc numCounter cmp numCounter, 12 jb next6 jmp LL2 LL2: mov numCounter, 0 call newline jmp next6 next6: inc si cmp si, 100 jb next5 jmp endBrutForce endBrutForce: call newline sPutStr mess3 mov ax, countPass call putdec$ sPutStr spaceBlank sPutStr mess4 mov ax, countComp call putdec$ sPutStr spaceBlank sPutStr mess5 mov ax, countSwap call putdec$ _Exit bubble ENDP END bubble