本文介绍了如何在MIPS组件中初始化庞大的数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我正在尝试将C代码转换为等效的MIPS:

For example, I'm trying to translate a C code into equivalent MIPS:

int a[50];
int i;
...
a[0] = 1;
a[1] = 1;
...

看着答案之一,除了别的没有别的办法吗?:

Looking at one of the answers, is there no other way than to do?:

     .data
array: .word  1,1,...,0  (till the 50th zero)

推荐答案

好,我要说的是您的描述没有错.但是,显然也可以使用循环来初始化数组.

Well, I would say that there is nothing wrong with what you've described. However, it is obviously also possible to use a loop to initialize an array.

initTable:

    la     $t0 table #$t0 stores first address in table
    addi   $t1 $t0 196 #$t1 stores address of one past end (49 * 4)
    addi   $t2 $zero 1

    intiTableLoop:

          sw   $t2 0($t0)
          addi $t0 $t0 4
          blt  $t0 $t1 initTableLoop

   sw $zero 0($t0)

   jr $ra

使用循环当然是初始化动态分配数组的唯一方法.

Using a loop is of course the only way that one could initialize a dynamically allocated array.

此后我从答案中发现: MIPS数据指令可以在mips中做到这一点如此:

I have since discovered from the answer here: MIPS Data Directives that one can do this in mips as so:

array: .word 1:49
       .word 0

冒号后面的数字表示应分配给冒号前面的值的单词数.这可能就是您想要的.

Where the number after the colon represents the number of words that should be assigned to the value before the colon. This is probably what you were looking for.

这篇关于如何在MIPS组件中初始化庞大的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 21:21