| | |
MIPS Help
Please support our Assembly advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: May 2007
Posts: 21
Reputation:
Solved Threads: 0
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)
#include<stdio.h> int main() { int a[3][3],i,j,k,min,max,col,count=0; printf("enter elements row-wise"); for(i=0;i<4;i++) { for(j=0;j<4;j++) { scanf("%d",&a[i][j]); } } for(i=0;i<4;i++) { min=a[i][0]; for(j=0;j<4;j++) { if(a[i][j]<=min) { min=a[i][j]; col=j; } } max=a[0][col]; for(k=0;k<4;k++) { if(a[k][col]>=max) { max=a[k][col]; } } if(max==min) { printf("saddle pt.at (%d,%d)",i+1,col+1); count++; } } if(count==0) printf("no saddle points"); }
•
•
Join Date: May 2007
Posts: 21
Reputation:
Solved Threads: 0
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)
.data strA: .asciiz "Saddle Point Value:" strB: .asciiz "There are no saddle points" newline: .asciiz "\n" space: .asciiz " " .align 2 A0: .word 1, 2, 3, 4 A1: .word 5, 6, 7, 8 A2: .word 5, 6, 7, 8 A3: .word 1, 2, 3, 4 .text main: li $t0, 4 la $t1, A0 li $t3, 4 li $t8, 4 li $s4, 0 loop1: lw $t2, 0($t1) move $t4, $t1 loop2: lw $t5, 0($t4) bgt $t5, $t2, Next move $t2, $t5 move $t6, $t4 Next: addi $t4, $t4, 4 addi $t3, $t3, -1 bne $t3, $zero, loop2 lw $t7, 0($t6) move $t9, $t7 loop3: lw $s0, 0($t9) blt $s0, $t7, Skip move $s1, $s0 Skip: addi $t9, $t9, 16 addi $t8, $t8, -1 bne $t8, $zero, loop3 bne $s1, $t2, No la $a0, strA li $v0, 4 syscall move $a0, $s1 li $v0, 1 syscall la $a0, newline li $v0, 4 syscall addi $s4, $s4, 1 No: addi $t1, $t1, 16 addi $t0, $t0, -1 bne $t0, $zero, loop1 beq $s4, $zero, Nos j e Nos: la $a0, strB li $v0, 4 syscall e: li $v0, 10 syscall
hm this line is bad:
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:
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)
lw $t7, 0($t6) // you putted the first element of t6 (A0 array) to t7 (which is 1) move $t9, $t7 // than you copied t7 to t9 and now t9 is 1. 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.
If you want to win, you must not loose (Alan Ford)
![]() |
Similar Threads
- Quick MIPS question (Assembly)
- i'm a rookie, please help with MIPS (Assembly)
- MIPS language question2 pls help.. (Assembly)
- MIPS language question pls help.. (Assembly)
- MIPS help (Assembly)
- Looking for a tutor for MIPS programming (Assembly)
- Mips Assembly porting from C (Assembly)
- Easy (I hope) MIPS (SPIM) Question (Assembly)
Other Threads in the Assembly Forum
- Previous Thread: please help meI have assignment in
- Next Thread: How could I enlarge text?
Views: 2265 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for Assembly
3d 68hc11 6811 80386 :( adress array asm assembler assembly boot bootloader buffer compression cursor debug directory division docs dos draw emulator endtask error exceptions file int10h integer intel interrupt interrupts language loop newbie nohau osdevelopment print program range read remainder shape string text theory tsr x86






