这是我第二次处理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
X_INPUT
数组中了,所以你把它们放在那里。你是不是指“从数组中加载”? - Michael