tags:

views:

111

answers:

1

Hi all, I've never used MIPS assembly before and it was just introduced in class. I'm working on a homework assignment, but I'm having some difficulty calling a function. Here's what I've worked out so far:

        .data
    .align 2    
    matrix_a:   .word 11, 23, 31, 46, 52, 66, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16

    .text
    .align 2
    .globl main

main:
    la $a0, matrix_a   #; Address of matrix_a
    addi $a1, 16       #; set the second argument to the size of matrix_a, 16
    jal matrix_print   #; and call the function

matrix_print:
    add $t3,$zero,$a0
    li $t2, 0                   #; And initialize $t2 = 0
    add $t4, $t2, $zero         #; Set $t4 = $t2, we will use $t4 for checking our loop
    add $t5,$zero,$a1           #; And $t5 is our max point
    Loop:
        bge $t4, $t5, Exit      #; If our index has reached our constraint, jump to exit
        add $t2,$zero,$t4       #; Otherwise, set $t2 to equal $t4
        add $t2, $t2, $t2       #; Double $t2
        add $t2, $t2, $t2       #; and double it again
        add $t1, $t2, $t3       #; and store $t2, the offset, + $t3, the initial address
        li $v0,1                #; Get ready to system call print an int
        lw $a0, 0($t1)          #; Pass in $t1 to print
        syscall                 #; Print        
        addi $t4,$t4,1          #; increment $t4 by 1
        j Loop
    Exit:
    li  $v0,10                  #; Exit
    syscall

The problem is that it is looping forever, so I believe that $a1 isn't coming through properly. This code work when I was setting the size directly in the function. Can anyone point me in the right direction? Thanks!

+1  A: 

In the line addi $a1, 16, what value does $a1 have before you add 16 to it?

Gabe
Awesome, I got it. Just poor syntax on my part- I want to set $a1 to 16, not add 16 to $a1. Working now, thanks! (For those reading this, what I wanted was: addi $a1, $zero, 16
Joe