944,073 Members | Top Members by Rank

Ad:
  • Assembly Discussion Thread
  • Unsolved
  • Views: 2779
  • Assembly RSS
May 16th, 2007
0

MIPS Help

Expand Post »
I need to write a program in MIPS that will find the saddle points of a 4x4 matrix. It will print the value of the saddle points and if there is no saddle points it will print a message that says so. A saddle point is a value which is a minimum in a row and the maximum in its column. I have written this program in c and it works and am having trouble converting it to assembly. My c code is below. I am having trouble putting all the loops in assembly. Any help is appreciated. thanks.

Assembly Syntax (Toggle Plain Text)
  1. #include<stdio.h>
  2.  
  3. int main()
  4. {
  5. int a[3][3],i,j,k,min,max,col,count=0;
  6. printf("enter elements row-wise");
  7.  
  8. for(i=0;i<4;i++)
  9. {
  10. for(j=0;j<4;j++)
  11. {
  12. scanf("%d",&a[i][j]);
  13. }
  14. }
  15.  
  16. for(i=0;i<4;i++)
  17. {
  18. min=a[i][0];
  19. for(j=0;j<4;j++)
  20. {
  21. if(a[i][j]<=min)
  22. {
  23. min=a[i][j];
  24. col=j;
  25. }
  26. }
  27. max=a[0][col];
  28. for(k=0;k<4;k++)
  29. {
  30. if(a[k][col]>=max)
  31. {
  32. max=a[k][col];
  33. }
  34. }
  35. if(max==min)
  36. {
  37. printf("saddle pt.at (%d,%d)",i+1,col+1);
  38. count++;
  39. }
  40. }
  41. if(count==0)
  42. printf("no saddle points");
  43. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ashkash is offline Offline
24 posts
since May 2007
May 16th, 2007
0

Re: MIPS Help

gcc -S prog.c
Then look at prog.s
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
May 17th, 2007
0

Re: MIPS Help

I have tried to write MIPS assembly code for this problem and am trying to convert my C code to assembly. Below is what I have and when I run it using PCSpim I get a lot of errors. If anyone can see what I am doing wrong or help me out in anyone I would really appreciate it. Thanks.

Assembly Syntax (Toggle Plain Text)
  1. .data
  2. strA: .asciiz "Saddle Point Value:"
  3. strB: .asciiz "There are no saddle points"
  4. newline: .asciiz "\n"
  5. space: .asciiz " "
  6. .align 2
  7. A0: .word 1, 2, 3, 4
  8. A1: .word 5, 6, 7, 8
  9. A2: .word 5, 6, 7, 8
  10. A3: .word 1, 2, 3, 4
  11.  
  12. .text
  13. main: li $t0, 4
  14. la $t1, A0
  15. li $t3, 4
  16. li $t8, 4
  17. li $s4, 0
  18. loop1: lw $t2, 0($t1)
  19. move $t4, $t1
  20. loop2: lw $t5, 0($t4)
  21. bgt $t5, $t2, Next
  22. move $t2, $t5
  23. move $t6, $t4
  24. Next: addi $t4, $t4, 4
  25. addi $t3, $t3, -1
  26. bne $t3, $zero, loop2
  27. lw $t7, 0($t6)
  28. move $t9, $t7
  29. loop3: lw $s0, 0($t9)
  30. blt $s0, $t7, Skip
  31. move $s1, $s0
  32. Skip: addi $t9, $t9, 16
  33. addi $t8, $t8, -1
  34. bne $t8, $zero, loop3
  35. bne $s1, $t2, No
  36. la $a0, strA
  37. li $v0, 4
  38. syscall
  39. move $a0, $s1
  40. li $v0, 1
  41. syscall
  42. la $a0, newline
  43. li $v0, 4
  44. syscall
  45. addi $s4, $s4, 1
  46. No: addi $t1, $t1, 16
  47. addi $t0, $t0, -1
  48. bne $t0, $zero, loop1
  49. beq $s4, $zero, Nos
  50. j e
  51. Nos: la $a0, strB
  52. li $v0, 4
  53. syscall
  54. e: li $v0, 10
  55. syscall
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ashkash is offline Offline
24 posts
since May 2007
May 17th, 2007
0

Re: MIPS Help

And those errors would be what exactly?
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
May 17th, 2007
0

Re: MIPS Help

hm this line is bad:

loop3: lw $s0, 0($t9)

The value of t9 is not an address its only 1. So you have illegal address exception. If your next question is why its 1 than the answer is:
Assembly Syntax (Toggle Plain Text)
  1. lw $t7, 0($t6) // you putted the first element of t6 (A0 array) to t7 (which is 1)
  2. move $t9, $t7 // than you copied t7 to t9 and now t9 is 1.
  3. loop3: lw $s0, 0($t9) // now you can see that t9 is the first element of A0 array and its not some address
Last edited by andor; May 17th, 2007 at 5:18 am.
Reputation Points: 251
Solved Threads: 29
Posting Whiz in Training
andor is offline Offline
274 posts
since Jun 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Assembly Forum Timeline: please help meI have assignment in
Next Thread in Assembly Forum Timeline: How could I enlarge text?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC