简体   繁体   English

MIPS:什么指令从 memory 获取数据?

[英]MIPS: What instructions fetches data from memory?

There are a multitude of different instructions in MIPS. MIPS 中有大量不同的指令。 I'm currently learning about data and instruction cache.我目前正在学习数据和指令缓存。

Instruction cache simply takes what it can so to say, depending on the block size it might utilize spatial locality and fetch multiple instructions.指令缓存只是简单地使用它可以这么说的内容,这取决于它可能利用空间局部性并获取多条指令的块大小。 But for data cache I have a harder time understanding when it fetches things from main memory and when it doesn't.但是对于数据缓存,我很难理解它什么时候从主 memory 获取东西,什么时候不获取。

For example, the instruction lw $t0, 0x4C($0) will fetch a word of data stored in address 0x4C and depending on data cache capacity, sets, block size and so forth it will temporarily store in in a block in the cache if for that adress the valid bit or tag doesn't exist there.例如,指令 lw $t0, 0x4C($0) 将获取存储在地址 0x4C 中的一个数据字,并且根据数据缓存容量、集合、块大小等,它将临时存储在缓存中的一个块中,如果那里不存在寻址有效位或标记的地址。

In my litterature, an addi instruction does not fetch from memory, why?在我的文献中,一条 addi 指令不会从 memory 获取,为什么? The only times it seems to need to fetch data from memory is when using the lw instruction, why?它似乎唯一需要从 memory 获取数据的时候是在使用 lw 指令时,为什么?

I also have a question regarding registers in MIPS.我还有一个关于 MIPS 寄存器的问题。 If we're simply doing the instructions over the registers, then there will be no access to any main memory, correct?如果我们只是通过寄存器执行指令,那么将无法访问任何主 memory,对吗? It will not even go to the data cache, correct?它甚至不会将 go 写入数据缓存,对吗? Are the registers the highest level in the memory heirarchy?寄存器是 memory 层次结构中的最高级别吗?

The reason addi doesn't "fetch from memory" is that it's using an immediate operand , as in, the program counter has already fetched the value that's going to be loaded. addi不“从内存中获取”的原因是它使用立即操作数,因为程序计数器已经获取了将要加载的值。 (Technically it is fetching from memory, since all code resides in some form of memory, but when literature refers to "memory" typically it's referring to a range of memory outside the program counter. When MIPS uses something like lw to load from memory, the CPU has no idea what value the destination register will have until the load is finished. (从技术上讲,它是从 memory 获取的,因为所有代码都以 memory 的某种形式存在,但是当文献提到“内存”时,它通常指的是程序计数器之外的 memory 范围。当 MIPS 使用类似lw的东西从 memory 加载时,在加载完成之前,CPU 不知道目标寄存器将具有什么值。

Just to illustrate this concept further, the original MIPS I architecture (which was used by the PlayStation 1) actually wouldn't finish loading from memory before the next instruction was already being worked on!只是为了进一步说明这个概念,原始的 MIPS I 架构(PlayStation 1 使用的架构)实际上不会在下一条指令已经开始之前完成从 memory 的加载!

lw $t0,0($a0)    ;load from the address pointed to by $a0
addi $t0,$t0,5   ;the value in $t0 hasn't been updated yet so this won't have the desired result.

The easiest solution to this was to put a nop after every lw .最简单的解决方案是在每个lw之后放置一个nop Chances are the version of MIPS you're using doesn't have this problem, so don't worry about it.很可能您使用的 MIPS 版本没有这个问题,所以不用担心。

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

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