Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

help!

Can someone help me with this one?
Add a variable to the bubblesort procedure that is set to 1 whenever a pair of values is exchanged within the inner loop. Use this variable to exit the sort before its normal completion if you discover that no exchange took place during a complete pass through the array. add in a loop counter or timmer to measure th difference it takes to input a randon ordered array of 50 numbers.

TITLE Bubble Sort and Binary Search B_main.asm)

; Bubble sort an array of signed integers, and perform
; a binary search.
; Main module, calls Bsearch.asm, Bsort.asm, FillArry.asm
; Last update: 1/18/02

INCLUDE Irvine32.inc
INCLUDE Bsearch.inc ; procedure prototypes


LOWVAL = -5000 ; minimum value
HIGHVAL = +5000 ; maximum value
ARRAY_SIZE = 50 ; size of the array

.data
array DWORD ARRAY_SIZE DUP(?)
StartTime DWORD ?


.code
main PROC
call Randomize

; Fill an array with random signed integers
INVOKE FillArray, ADDR array, ARRAY_SIZE, LOWVAL, HIGHVAL

; Display the array
INVOKE PrintArray, ADDR array, ARRAY_SIZE
call WaitMsg

;Starts counting elapse time
INVOKE GetTickCount
move StartTime, eax

; Perform a bubble sort and redisplay the array
INVOKE BubbleSort, ADDR array, ARRAY_SIZE

INVOKE GetTickCount
sub eax, StartTime
INVOKE PrintArray, ADDR array, ARRAY_SIZE

; Demonstrate a binary search
call AskForSearchVal ; returned in EAX
INVOKE BinarySearch,
ADDR array, ARRAY_SIZE, eax

***************************
call ShowResults

exit
main ENDP

;--------------------------------------------------------
AskForSearchVal PROC
;
; Prompt the user for a signed integer.
; Receives: nothing
; Returns: EAX = value input by user
;--------------------------------------------------------
.data
prompt BYTE "Enter a signed decimal integer "
BYTE "to find in the array: ",0
.code
call Crlf
mov edx,OFFSET prompt
call WriteString
call ReadInt
ret
AskForSearchVal ENDP

;--------------------------------------------------------
ShowResults PROC
;
; Display the resulting value from the binary search.
; Receives: EAX = position number to be displayed
; Returns: nothing
;--------------------------------------------------------
.data
msg1 BYTE "The value was not found.",0
msg2 BYTE "The value was found at position ",0
.code
.IF eax == -1
mov edx,OFFSET msg1
call WriteString
.ELSE
mov edx,OFFSET msg2
call WriteString
call WriteDec
.ENDIF
call Crlf
call Crlf
ret
ShowResults ENDP

END main
Sign In or Register to comment.