這只是我第二次處理MIPS組件(即任何類型的組件),所以請溫和。所以我從頭開始爲MIPS提供了一個多功能。這比我想象的要容易 - 我測試了它,它對於一個值是完美的。不幸的是,當數組進入圖片時,我完全失去了。如何遍歷MIPS中的數組?
我甚至不知道如何開始。我感到遲鈍,因爲我不能問一個具體的問題,因爲我不明白這個大想法。我分配的空間,有數組常量,但真的不知道如何:
A.)加載常數值(例如5,2,3,10,7)進入陣列。
B.)讓我的外環繼續。
我的代碼如下,所有我需要的是一個辦法讓我的外循環下去。有任何想法嗎??
/*
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
你是什麼意思的「加載到陣列」?值5,2,3,10,7已經存在於'X_INPUT'數組中,因爲在聲明數組時它們放在那裏。你的意思是「從陣列加載」? – Michael