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 423,507 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 4,664 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: Programming Forums
Views: 1050 | Replies: 1
Reply
Join Date: Sep 2007
Posts: 12
Reputation: -EquinoX- is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
-EquinoX- -EquinoX- is offline Offline
Newbie Poster

function error in MIPS

  #1  
Oct 20th, 2007
my code is
[code]

however whenever I tried to print something inside the function it always gives me a bad address error, can someone please tell me why?? this is my code:
largest : #Function prologue
	  subu $sp, $sp, 56
	  sw $a1, 44($sp)
	  sw $a0, 40($sp)
	  sw $ra, 36($sp)
	  sw $fp, 32($sp)
	  sw $s7, 28($sp)
	  sw $s6, 24($sp)
	  sw $s5, 20($sp)
	  sw $s4, 16($sp)
	  sw $s3, 12($sp)
	  sw $s2, 8($sp)
	  sw $s1, 4($sp)
	  sw $s0, 0($sp)
	  addiu $fp, $sp, 56
	  
	  lw $s0, 0($a0)				# $t0 = first elements in the numbers array
	  li $s2, 1					# $t2 = 1
	  li $s3, 0					# $t3 = 0
	  
iterate : #Loop Test  
	  add $s1, $s2, $s2     			# quadruple i to get offset for numbers[i]
	  add $s1, $s1, $s1
          add $s5, $s1, $a0     			# compute address of numbers[i]
	  lw  $s7, 0($s5)				# t7 = value stored at numbers[i]
          
	  addi $s2, $s2, 1				# $t2 ++ 
	  beq  $s3, $a1, result		 		# if $t3 equals to numElements then count result
	  addi $s3, $s3, 1				# $t3 ++   
	  
	  #Loop Body
	  slt $s4, $s0, $s7				# $t4 = 1 if $t0 is less than $t7
	  beq $s4, $zero, iterate			# if $t5 not equal to zero then iterate again
	  lw $s0, 0($s5)				# else $t0 = $t7
	  j iterate					# iterate
		
result:	  add $v0, $s0, $zero				# put the result of the largest number into $v0
	
	  #Function epilogue
	  lw $a1, 44($sp)
	  lw $a0, 40($sp)
	  lw $ra, 36($sp)
	  lw $fp, 32($sp)
	  lw $s7, 28($sp)
	  lw $s6, 24($sp)
	  lw $s5, 20($sp)
	  lw $s4, 16($sp)
	  lw $s3, 12($sp)
	  lw $s2, 8($sp)
	  lw $s1, 4($sp)
	  lw $s0, 0($sp)
	  addiu $sp, $sp, 56
	  jr $ra
	  
	  
average : #Function prologue
	   subu $sp, $sp, 56
	   sw $a1, 44($sp)
	   sw $a0, 40($sp)
	   sw $ra, 36($sp)
	   sw $fp, 32($sp)
	   sw $s7, 28($sp)
	   sw $s6, 24($sp)
	   sw $s5, 20($sp)
	   sw $s4, 16($sp)
	   sw $s3, 12($sp)
	   sw $s2, 8($sp)
	   sw $s1, 4($sp)
	   sw $s0, 0($sp)
	   addiu $fp, $sp, 56
           
           
           li $s2, 0					# $s2 = 0
           
iterate1 : #Loop Test
	  add $s1, $s2, $s2				# quadruple i to get offset for numbers[i]		
	  add $s1, $s1, $s1
	  add $s5, $s1, $a0
	  lw $s0, 0($s5)
         
	  add $s4, $s4, $s0				# s4 = total addition of the array to numbers[i]
	  
	  #LoopBody
	  addi $s2, $s2, 1			        # $s2 ++ 
	  beq  $s3, $a1, result1	 		# if $t3 equals to numElements then count result 
	  addi $s3, $s3, 1				# $t3 ++  
	  j iterate1					# iterate1
	  
result1 : div $s4, $a1
	  addi $a2, $a1, 0 
	  mfhi $a1
	  
	  addi $a0, $a1, 
	  
	  
	  mflo $a0
	   
	  jal printAverage	 	  
	  
	  #Function epilogue
	  lw $a1, 44($sp)
	  lw $a0, 40($sp)
	  lw $ra, 36($sp)
	  lw $fp, 32($sp)
	  lw $s7, 28($sp)
	  lw $s6, 24($sp)
	  lw $s5, 20($sp)
	  lw $s4, 16($sp)
	  lw $s3, 12($sp)
	  lw $s2, 8($sp)
	  lw $s1, 4($sp)
	  lw $s0, 0($sp)
	  addiu $sp, $sp, 56
	  jr $ra

thanks
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2007
Posts: 12
Reputation: -EquinoX- is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
-EquinoX- -EquinoX- is offline Offline
Newbie Poster

Re: function error in MIPS

  #2  
Oct 20th, 2007
I think i made a mistake on the procedure convention here, cause everytime I call the largest function and then call the average function. The register $s0-$s7 isn't set back to zero. What's wrong here??
Reply With Quote  
Reply

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

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

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Assembly Forum

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