Link to home
Start Free TrialLog in
Avatar of kuntilanak
kuntilanakFlag for United States of America

asked on

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

Avatar of Mc7400
Mc7400
Flag of United States of America image

Line 89 should be jr $ra
jal is used to call, jr is used to return
Avatar of kuntilanak

ASKER

changed that as well and doesn't work still...
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.
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.
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.
trust me changing the jal to jr doesn't have any effects of resolving the error, I tried...
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.
See you tomorrow
Avatar of Infinity08
>> Line 89 should be jr $ra
>> jal is used to call, jr is used to return

Maybe now, you believe me, kuntilanak ;)

        https://www.experts-exchange.com/Programming/Languages/Assembly/Q-23900622-what's-wrong-with-this-MIPS-code.html#22948199
>>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...
>>Maybe now, you believe me, kuntilanak ;)

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

j/k ;)
>>j/k ;)

Infinity maybe you could help me out here....
ASKER CERTIFIED SOLUTION
Avatar of Infinity08
Infinity08
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
yes, that's why! thanks