1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Assembly Programming Help

  1. May 16, 2007 #1
    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. jcsd
  3. May 16, 2007 #2
    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?
  4. May 16, 2007 #3
    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):

    int main()
       int a[3][3],i,j,k,min,max,col,count=0;
       printf("enter elements row-wise");
          printf("saddle pt.at (%d,%d)",i+1,col+1);
      printf("no saddle points");  
    Code (Text):

    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

    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
        move $a0, $s1
        li  $v0, 1
        la  $a0, newline
        li  $v0, 4          
        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
    e:  li $v0, 10
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook