This is only my second time dealing with MIPS assembly (i.e. or any kind of assembly), so please be gentle. So I made a multiply function for MIPS from scratch. That was easier than I thought -- I tested it and it works perfectly for one value. Unfortunately, I am COMPLETELY lost when arrays come into the picture.
I do not even know how to get started. I feel retarded because I can't ask a specific question because I don't understand the big idea. I allocated space, have constant values for the arrays, but don't really know how to:
A.) Load the constant values (e.g. 5,2,3,10,7) into the arrays.
B.) Get my outer loop going.
My code is below and all I need is a way to get my outer loop going. Any ideas??
/*
Name: MrPickl3
Date: October 10, 2013
Purpose: Program creates a multiply function from scratch. Uses two arrays to
test the program.
*/
#include <xc.h>
. data
X: .space 80
Y: .space 80
N: .space 4
MAC_ACC .word 0x00000000
.text
.globl main
main:
li t0, 0x00000000 //i = 0
li t1, 0x00000005 //Offset of array
li t2, MAC_ACC //Mac_acc (i.e. product register)
lw t9, 0(t2) //Refers to MAC_ACC's data
la t3, X //Address of X[0]
lw t4, 0(t3) //Data of X
la t5, Y //Address of Y[0]
lw t6, 0(t5) //Data of Y
loop:
addiu t0, t0, 4 //i++
//t4 = x[i]
//t6 = y[i]
//t7 = counter
mult:
beq t6, 0, loop //Check if y = 0. Go to loop, if so.
andi t7, t6, 1 /*We want to know the nearest power of two.
We can mask the last bit to
test whether or not there is a power of two
left in the multiplier.*/
beq t7, 0, shift //If last bit is zero, shift
addu t9, t9, t4 //Add multiplicand to product
shift:
sll t3, t3, 1 //Multiply x[i] by 2
srl t4, t4, 1 //Multiply y[i] by 2
lab2_done:
j lab2_done
nop
.end main
X_INPUT: .word 5,2,3,10,7
Y_INPUT: .word 6,0,8,1,2
N_INPUT: .word 5