Question about my MIPS Program

Discussion in 'C++' started by Milk, Apr 14, 2004.

  1. Milk

    Milk Guest

    Hi,
    i got a program working half part and my program is suppose to do 4*4 matrix
    can any one help me to check it? i dunno whic part i did wrong thx~~

    Here is the program :::::
    .data
    arrayA: .space 1024
    arrayB: .space 1024
    arrayC: .space 1024
    str: .asciiz " "

    .text
    main:
    move $s1, $zero #initial j to 0
    move $s2, $zero #initial i to 0
    move $s3, $zero #initial k to 0
    li $t4, 4
    move $t0, $zero #initial array A to 0
    move $t1, $zero #initial array b to 0
    move $t2, $zero #initial array c to 0


    L1:
    mul $s4, $s1, $s2 #s4 = ixj
    la $t6, arrayA($t0) #loading the array address
    sw $s5, 0($t6) #a[j] = ixj
    addiu $t0, $t0, 4 #move to next array location in matrix a

    la $t7, arrayB($t1) #loading the array address
    sw $s4, 0($t7) #b[j] = ixj
    addiu $t1, $t1, 4 #move to next array location in matrix b
    #-----------------------------------------------------------------------
    li $v0, 1 #print int
    addu $a0, $s4, $zero #print out matrix a[j]
    syscall

    #-------------------------------------------------------------------------

    addiu $s2, $s2, 1 #s2 i add 1
    bne $s2, $t4, L1 #if s2 not equal 4 go back L1
    li $s2, 0 #initial i to 0
    addiu $s1, $s1, 1 #s1 j add 1
    bne $s1, $t4, L1
    #--------------------------------------------------------------

    move $s1, $zero #reset j to 0
    move $s2, $zero #reset i to 0
    move $s6, $zero
    move $t0, $zero #reset array A to 0
    move $t1, $zero #reset array b to 0
    move $t6, $zero #reset t6
    move $t7, $zero #reset t7

    L2:
    la $t8, arrayC($t2) #load an array address
    sw $s6, 0($t8) #arrayC = s6

    L3:
    la $t3, arrayA($t0) #load value from array A to t3
    lw $s8, 0($t3)
    la $t9, arrayB($t1) #load value from array B to t3
    lw $s7, 0($t9) #c[k] = 0
    mul $t5, $s8, $s7 #a[k][j]b[j]
    add $s7, $s7, $t5 #c[k]=c[k]+a[k][j]*b[j]
    #-----------------------------------------------------------------------
    li $v0, 1 #print int
    addu $a0, $s7, $zero #print out matrix a[j]
    syscall

    #------
    mul $t6, $s3, $t4 #t6= k*16
    add $t6, $t6, $s1 #t6= k*16+j
    mul $t0, $t6, 4 #move to next address in arrayA

    mul $t7, $s1, $t4 #t6= j*16
    add $t7, $t7, $s2 #t6= j*16+i
    mul $t0, $t7, 4 #move to next address in arrayB

    addi $s1, $s1, 1 #j+1
    bne $s1, $t4, L3
    add $s6, $s0, $zero
    move $s1, $zero
    addi $t8, $t8, 4 #add address of arrayC


    addi $s3, $s3, 1
    bne $s3, $t4, L2
    move $s3, $zero #reset k to zero

    addi $s2, $s2, 1
    bne $s2, $t4, L2


    exit:
    li $v0, 10
    syscall




    ~ Let us linux ~


    -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
    http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
    -----== Over 100,000 Newsgroups - 19 Different Servers! =-----
    Milk, Apr 14, 2004
    #1
    1. Advertising

  2. Milk <> spoke thus:

    > i got a program working half part and my program is suppose to do 4*4 matrix
    > can any one help me to check it? i dunno whic part i did wrong thx~~


    PLEASE read the welcome message - this is not comp.lang.MIPS.assembly!

    http://www.slack.net/~shiva/welcome.txt
    http://www.parashift.com/c -faq-lite/

    --
    Christopher Benson-Manica | I *should* know what I'm talking about - if I
    ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
    Christopher Benson-Manica, Apr 14, 2004
    #2
    1. Advertising

  3. Milk wrote:
    [One of the least topical posts ever seen on this group.]

    Yeah, I think we've had about enough of you.

    Shall we, gentlemen?

    *PLONK*

    -Kevin
    --
    My email address is valid, but changes periodically.
    To contact me please use the address from a recent posting.
    Kevin Goodsell, Apr 14, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Klejmann

    data hazards and the mips

    Klejmann, Jun 17, 2004, in forum: VHDL
    Replies:
    1
    Views:
    1,603
    Just an Illusion
    Jun 18, 2004
  2. Andreas Weichert
    Replies:
    1
    Views:
    748
    Peter van Merkerk
    Nov 25, 2003
  3. Replies:
    0
    Views:
    467
  4. niclane
    Replies:
    0
    Views:
    419
    niclane
    Dec 9, 2005
  5. Replies:
    4
    Views:
    1,106
    Nick Craig-Wood
    Jan 11, 2006
Loading...

Share This Page