Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 294
  • Last Modified:

what's the problem with this MIPS code?

This is really weird.. when I try to run ths code using PC Spim and execute it directly using F5, it complaints that a bad data address occured and ignored.. however when I run this step by step at a time, when it reaches the end of the process.. it doesn't give me that error.. so I am confused why this error could happen?? Can someone help me to point it out..
.text
	.globl _ifsGalore
	_ifsGalore:
			# Function Entry
	sw $ra,-72($sp)
	sw $fp,-76($sp)
	add  $fp, $zero, $sp
	subu $sp, $sp, 76
	 # MOVE 
	add $t0,$zero,5
	sw  $t0,-48($fp)
	 # MOVE 
	add $t0,$zero,6
	lw  $t1,-48($fp)
	mul $t1,$t1,4
	add  $t2,$zero,-44
	add $t1,$t2,$t1
	add $t1,$fp,$t1
	sw  $t0,($t1)
	 # MOVE 
	add $t0,$zero,5
	sw  $t0,-56($fp)
	 # MOVE 
	lw  $t0,-56($fp)
	mul $t0,$t0,4
	add  $t1,$zero,-44
	add $t0,$t0,$t1
	add $t0,$fp,$t0
	lw  $t1,($t0)
	sw $t1,-52($fp)
	 # MOVE 
	add $t0,$zero,7
	lw  $t1,-52($fp)
	mul $t1,$t1,4
	add  $t2,$zero,-44
	add $t1,$t2,$t1
	add $t1,$fp,$t1
	sw  $t0,($t1)
	 # MOVE 
	add $t0,$zero,6
	sw  $t0,-68($fp)
	 # MOVE 
	lw  $t0,-68($fp)
	mul $t0,$t0,4
	add  $t1,$zero,-44
	add $t0,$t0,$t1
	add $t0,$fp,$t0
	lw  $t1,($t0)
	sw $t1,-64($fp)
	 # MOVE 
	lw  $t0,-64($fp)
	mul $t0,$t0,4
	add  $t1,$zero,-44
	add $t0,$t0,$t1
	add $t0,$fp,$t0
	lw  $t1,($t0)
	sw $t1,-60($fp)
	 # MOVE 
	add $t0,$zero,8
	lw  $t1,-60($fp)
	mul $t1,$t1,4
	add  $t2,$zero,-44
	add $t1,$t2,$t1
	add $t1,$fp,$t1
	sw  $t0,($t1)
			# Function Ends
	LABEL1:
			# Exit Sequence
	lw $ra,-72($fp)
	add  $sp, $zero, $fp
	lw $fp,-76($fp)
	jal $ra
	.globl main
	main:
			# Function Entry
	sw $ra,-4($sp)
	sw $fp,-8($sp)
	add  $fp, $zero, $sp
	subu $sp, $sp, 8
			# Function call
	jal _ifsGalore
	add $sp,$sp,0
			# Function Ends
	LABEL2:
			# Exit Sequence
	lw $ra,-4($fp)
	add  $sp, $zero, $fp
	lw $fp,-8($fp)
	jal $ra

Open in new window

0
kuntilanak
Asked:
kuntilanak
  • 7
  • 5
  • 3
1 Solution
 
Mc7400Commented:
Line 89 should be jr $ra
jal is used to call, jr is used to return
0
 
kuntilanakAuthor Commented:
changed that as well and doesn't work still...
0
 
Mc7400Commented:
Run it with step by step and make sure the registers have the same values when return as the entry point, I don't have any tool here to check it.
Please provide the error message.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
kuntilanakAuthor Commented:
yes they do have the same values at entry and return I guess.... when I run it step by step in SPIM it doesn't complain however when run at once, it complaints: as I said the error was:

bad data address occured and ignored.
0
 
Mc7400Commented:
If you are trying to return at line 72 then it should be jr as well.
you may have to select delayed branches and delayed load in settings.
0
 
kuntilanakAuthor Commented:
trust me changing the jal to jr doesn't have any effects of resolving the error, I tried...
0
 
Mc7400Commented:
Have you selected delayed branches and delayed load in settings?
One more thing that there is no need to save $ra register, delete all the lines which save or retrieve the $ra.
I've just downloaded PCSpim and the code worked perfectly after the mentioned changes.
0
 
Mc7400Commented:
See you tomorrow
0
 
Infinity08Commented:
>> Line 89 should be jr $ra
>> jal is used to call, jr is used to return

Maybe now, you believe me, kuntilanak ;)

        http://www.experts-exchange.com/Programming/Languages/Assembly/Q-23900622-what's-wrong-with-this-MIPS-code.html#22948199
0
 
kuntilanakAuthor Commented:
>>One more thing that there is no need to save $ra register, delete all the lines which save or retrieve the >>$ra.

which part is it? I can only see I save and retrieve $ra when I do a function call and return back again from it...
0
 
kuntilanakAuthor Commented:
>>Maybe now, you believe me, kuntilanak ;)

I always believed you since the beginning, :D
0
 
Infinity08Commented:
>> I always believed you since the beginning, :D

j/k ;)
0
 
kuntilanakAuthor Commented:
>>j/k ;)

Infinity maybe you could help me out here....
0
 
Infinity08Commented:
The 'add' on line 64 overflows. Make sure that the calculations you do are correct. The $t1 value is too big to add to the frame pointer.
0
 
kuntilanakAuthor Commented:
yes, that's why! thanks
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now