简体   繁体   English

MIPS lw语义:“ lw $ t2,$ t0”和“ lw $ t2,($ t0)”之间的区别?

[英]MIPS lw semantics: difference between “lw $t2, $t0” and “lw $t2, ($t0)”?

I'm picking up some MIPS in this quick tutorial , where the author distinguishes between these two lw instructions: 我将在此快速教程中学习一些MIPS,作者在其中区分了这两个lw指令:

lw $t2, $t0 # copy word (4 bytes) at source RAM location to destination register.

lw $t2, ($t0) # load word at RAM address contained in $t0 into $t2

I feel like the author's two comments mean the same... 我觉得作者的两条评论是一样的...
When I think of these registers as loosely pointers in C++ (of course they're not since registers contain both memory addresses and actual data), both statements seem to do the same thing: copying $t0's "pointee" into $t2, so that $t2's actual value is $t0's "pointee", basically: 当我将这些寄存器视为C ++中的松散指针时(当然,由于寄存器同时包含内存地址和实际数据,所以它们并非如此),这两个语句似乎都在做相同的事情:将$ t0的“ pointee”复制到$ t2中,这样$ t2的实际值是$ t0的“ pointee”,基本上是:

Word * $t0, $t2; //some hypothetical pointers
Word someData=1111000011110000.... //some hypothetical type (32 bits in total)
someData = *$t0; //de-reference $t0 and copy its value into someData
$t2 = someData; //impossible in real C++ but you know what I mean

Is there any difference between those two instructions at all? 这两条指令之间有什么区别吗? What about lw $t2, 0($t0) and lw $t2, (0)$t0 ? lw $t2, 0($t0)lw $t2, (0)$t0呢? I'm so confused... 我很混乱...

lw $t2, $t0 isn't a MIPS instruction --- I suspect you may have misread the page. lw $t2, $t0不是MIPS指令---我怀疑您可能误读了页面。

In general, in assembler-land, (thing) or [thing] is the common convention for value at address thing . 通常,在汇编程序领域, (thing)[thing]地址thing的通用约定。 So lw $t2, ($t0) means load the word at the address in $t0 . 所以lw $t2, ($t0)表示将单词加载到$t0中的地址 Yes, this is exactly how pointers work. 是的,这正是指针的工作方式。 It's the equivalent of, in C: 在C中相当于:

t2 = *(uint32_t*)t0;

It is also the same instruction as lw $t2, 0($t0) . 它也与lw $t2, 0($t0) The assembler just allows you to emit the number if it's 0; 如果数字为0,则汇编器只允许您发出该数字;否则为0。 the number is an offset applied to $t0 , so the address accessed is $t0+1234 . 该数字是应用于$t0的偏移量,因此访问的地址是$t0+1234 lw $t2, 1234($t0) is: lw $t2, 1234($t0)是:

t2 = *(uint32_t*)(t0 + 1234);

MIPS is very regular, unlike x86, and the only instructions that touch memory are the load and store instructions. 与x86不同,MIPS非常常规,触摸存储器的唯一指令是加载和存储指令。 You won't see this construction anywhere else. 在其他任何地方都看不到这种结构。

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

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