# Homework Help: Assembly Programming Help

1. May 16, 2007

### ashkash

1. The problem statement, all variables and given/known data
Write a program using the MIPS ISA to find the saddle point of a 4x4 matrix. Print the value of the saddle points or if there is no saddle point print a message that says so. A saddle point is a value that is the minimum value in a row and also the maximum value in its column.

2. Relevant equations

3. The attempt at a solution
I have written a program in c to do this and it works fine. The problem I am having is converting it to assembly. Any help would be appreciated. I can show my c code if it would be helpful.

2. May 16, 2007

### MeJennifer

What have you done so far?

For instance:
Did you decide on a layout of the memory locations of the matrix elements?
Which variables can you assign to a permanent register?
Can you take advantage of iteration over the matrix elements using indirect adressing?

3. May 16, 2007

### ashkash

So far I have written the program in C and am trying to convert that to assembly. I have written some code in assembly which is just a conversion of my C program, but am getting multiple errors. I am posting both to see if anyone can notice what I am doing wrong. I am using PCSpim to execute the assembly code. Thanks.

Code (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)
{
count++;
}
}
if(count==0)
}

Code (Text):

.data
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