MIPS, Dealing With Arrays and Lists

This topic contains 2 replies, has 3 voices, and was last updated by  ChrisImgtec 3 years, 5 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #31686

    thorax232
    Member

    I’m having a hard time with lists and using them properly and haven’t been able to find much help so far.

    I have this method written out in Java:

    public static void getQuot(int[] r, int[] q) {

    int i = 0;
    while(r[i+1] != 0) {
    q[i+1] = r / r[i+1];
    r[i+2] = r
    % r[i+1];

    System.out.print(q[i+1] + ", ");
    i++;
    }
    }

    I have this so far in MIPS (as far as the method goes):

    	# get Quotients, store to q
    li $t1,0 # i
    getQuot:
    add $t2,$t1,4 # i + 1
    add $t3,$t1,8 # i + 2
    la $a0,r
    lw $t8,$t1($a0) # load t8 & t9 for division
    lw $t9,$t2($a0)
    div $t8,$t9
    mflo $t4
    sw $t4,$t3($a0) # store quotient in r[i+2]
    la $a0,q
    mfhi $t4
    sw $t4,$t2($a0) # store remainder in r[i+1]
    addi $t1,$t1,1 # i++
    bnez $t1($a0),getQuot

    I also have these list in .data if that’s relevant:

    .data
    r: .word 0:100
    q: .word 0:100

    The problem I’m having is with doing something like lw $t8,$t1($a0), from the errors I’m getting I’m assuming I can’t use a register to denote a location on the list? If so, how can I go about creating this loop properly?

    #38672

    Sean
    Moderator

    What debugger do you have available?

    Can you step through and inspect what is being loaded into the registers here?

    #38673

    ChrisImgtec
    Moderator

    add $t2, $t1, $a0
    lw t8 ($t2)

Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic.