User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Assembly section within the Software Development category of DaniWeb, a massive community of 375,214 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,275 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Assembly advertiser:
Views: 913 | Replies: 2
Reply
Join Date: Apr 2008
Posts: 31
Reputation: Spagett912 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Spagett912's Avatar
Spagett912 Spagett912 is offline Offline
Light Poster

Bubble Sort/Random Numbers

  #1  
May 3rd, 2008
Once again I have found myself stuck on another problem in assembly langauge because it owns me. I am trying to write a program that uses the Bubble sort algorithm but to make things challenging I am required to use Local Variable. And that must be based off of this C++ coding:


function BubbleSort(int & array, int count)
{
int x, n=count ,y; //<---Create locals for these

for(x=0; x<n; x++)

{
 for(int y=0; y<x; y++)
  {
   if(array[y]>array[y+1])
        {
      int temp = array[y+1];
      array[y+1] = array[y];
     array[y] = temp;
     }
    }
}


Next I have to let this module print out the array as loaded with
random number (The "fill array" module does this). The array has 100
elements so I have to let PrintArray produce a 10x10 display of numbers.


This has proven difficult so unfortunately this is all I have

INCLUDE Irvine32.inc

.data
count = 100
array WORD count DUP(?)

.code
main PROC

	push OFFSET array
	push COUNT
	call ArrayFill
	
	exit

main ENDP

; Fills an array with 16-bit random integers.

ArrayFill PROC	
	push	ebp
	mov	ebp,esp
	pushad			; save registers
	mov	esi,[ebp+12]	; offset of array
	mov	ecx,[ebp+8]	; array size
	cmp	ecx,0		; ECX == 0?
	je	L2			; yes: skip over loop
    
L1:
	mov	eax,10000h	; get random 0 - FFFFh
	call	RandomRange	; from the link library
	mov	[esi],ax
	add	esi,TYPE WORD
	loop	L1

L2:	popad			; restore registers
	pop	ebp
	ret	8			; clean up the stack
ArrayFill ENDP

END main

So if anyone has any comments sugguestions or peices of coding to help me get the ball rolling, that would be extremely helpful
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2008
Posts: 31
Reputation: Spagett912 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Spagett912's Avatar
Spagett912 Spagett912 is offline Offline
Light Poster

Re: Bubble Sort/Random Numbers

  #2  
May 4th, 2008
I have a bit of better Coding to go by so here's the new stuff.


INCLUDE Irvine32.inc

.data
count = 100
array WORD count DUP(?)

.code
main PROC

	push OFFSET array
	push COUNT
	call ArrayFill
	
	push OFFSET array
	push COUNT
	call PrintArray
	
	push OFFSET array
	push COUNT
	call BubbleSort
	
	push OFFSET array
	push COUNT
	call PrintArray
	
	exit

main ENDP

; Fills an array with 16-bit random integers.

ArrayFill PROC	
	push	ebp
	mov	ebp,esp
	pushad			; save registers
	mov	esi,[ebp+12]	; offset of array
	mov	ecx,[ebp+8]	; array size
	cmp	ecx,0		; ECX == 0?
	je	L2			; yes: skip over loop
    
L1:
	mov	eax,10000h	; get random 0 - FFFFh
	call	RandomRange	; from the link library
	mov	[esi],ax
	add	esi,TYPE WORD
	loop	L1

L2:	popad			; restore registers
	pop	ebp
	ret	8			; clean up the stack
ArrayFill ENDP

END main
Reply With Quote  
Join Date: Apr 2008
Posts: 31
Reputation: Spagett912 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Spagett912's Avatar
Spagett912 Spagett912 is offline Offline
Light Poster

Re: Bubble Sort/Random Numbers

  #3  
May 12th, 2008
Ok. For anyone who's been looking at this, I've made a slight modification to the program. I still can't get it to print out 10x10 and can't get a bubble sort algorithm to work. Here's what I got.

TITLE Demonstrate reference parameters   (ArrayFill.asm)

; Last update: 06/01/2006

INCLUDE Irvine32.inc

.data
count = 100
array WORD count DUP(?)

.code
main PROC



	push OFFSET array
	push COUNT
	call ArrayFill
	
	;push OFFSET array
	;push COUNT
	;call BubbleSort
	
	push OFFSET array
	push COUNT
	call PrintArray
	
	exit

main ENDP

; Fills an array with 16-bit random integers.

ArrayFill PROC	
	push	ebp
	mov	ebp,esp
	pushad			; save registers
	mov	esi,[ebp+12]	; offset of array
	mov	ecx,[ebp+8]	; array size
	cmp	ecx,0		; ECX == 0?
	je	L2			; yes: skip over loop
    
L1:
	mov	eax,100	; get random 0 - FFFFh
	call	RandomRange	; from the link library
	;call WriteInt
	mov	[esi],ax
	add	esi,TYPE WORD
	loop	L1

L2:	popad			; restore registers
	pop	ebp
	ret	8			; clean up the stack
ArrayFill ENDP



PrintArray PROC

push	ebp
	mov	ebp,esp
	pushad			; save registers
	mov	esi,[ebp+12]	; offset of array
	mov	ecx,[ebp+8]	; array size
	
L1:	

mov ax,[esi]
movzx eax,ax
call WriteInt


	popad			; restore registers
	pop	ebp
	
	mov eax,ecx
	mov ebx, 10
	
	cdq
	
	div ebx
	
	cmp edx,0
	je newspace
	
	jmp continue
	
	newspace: call crlf
	
	continue: loop L1
	
	;inc ebx
	;cmp ebx, 10

	

ret 8

PrintArray ENDP



;BubbleSort PROC

;pop ebx
;pop ebp
;pop eax
;pop edx
;pop ecx

;BubbleSort ENDP

END main
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Assembly Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the Assembly Forum

All times are GMT -4. The time now is 3:07 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC