简体   繁体   English

数组如何存储在寄存器文件中?

[英]How are arrays stored in register files?

I am looking at a 32x32 register file, with $s0-$s7, $t0-$t9, $zero, $a0-$a3, $v0-$v1, $gp, $fp, $ra, and $at. 我正在看一个32x32寄存器文件,其中有$ s0- $ s7,$ t0- $ t9,$ zero,$ a0- $ a3,$ v0- $ v1,$ gp,$ fp,$ ra和$ at。

My question is how is an array stored in these register files? 我的问题是如何在这些寄存器文件中存储数组? Aren't they only each 32-bits wide? 他们不是只有32位宽吗?

For example, given base address of an array A is $s3, if I were to give instruction to get A[8]: 例如,如果我要给出指令以获得A [8],则给定数组A的基地址为$ s3:

lw $t0, 32($s3)

How does it retrieve the data? 它如何检索数据?

Array access is made through pointer (something the C people are very familiar with), so the register simply holds the base address of the array. 数组访问是通过指针进行的(C程序员非常熟悉),因此寄存器仅保存数组的基地址。 You are then adding 8 * 4 = 32 bytes to that base address to get the address of the 8th element and finally dereferencing that pointer (which means seeing what's at that address) to get the value (with the lw instruction). 然后,您要向该基地址添加8 * 4 = 32个字节,以获取第8个元素的地址,并最终取消对该指针的引用(这意味着查看该地址的内容)以获取值(使用lw指令)。

The instruction you have shown is the translation of this C code: 您显示的指令是此C代码的翻译:

t0 = *(s3 + 8)  // same as s3[8]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM