这个MIPS汇编程序中的lw和la有什么区别?

What is the difference between lw and la in this program of MIPS assembly?

#enter a string and show it 

.data 
prompt: .asciiz "enter a string >"
input_str: .space 81
input_sz: .word 80

.text

main:

# display the prompt
li $v0, 4
la $a0, prompt
syscall

# type a string, and save the input
li $v0, 8 # store the string in $v0
la $a0, input_str
lw $a1, input_sz 
syscall

# display the inputted string
li $v0, 4
la $a0, input_str
syscall

#terminate the program
li $v0, 10  
syscall

上面的程序显然工作正常。
lw 更改为 la 没有任何区别。
IE。该程序仍然有效。

那么,这个MIPS汇编程序中lwla有什么区别呢?

Changing lw to la makes no difference.
I.e. the program still works.

...但这并不意味着指令具有相同的效果。

如果在以下 C 指令中将 100 替换为 10000fgets(fl,buffer,100),程序也很有可能仍然可以运行!

So, What is the difference between lw and la in this program of MIPS assembly?

lw

lw 加载存储在特定地址的值。所以 lw $a1, input_sz 会将值 80 加载到寄存器 a1 中,因为值 80 存储在标签 input_sz.

指定的地址中

la

la 将标签本身的地址加载到寄存器中。例子:如果标号input_sz位于地址100,值100将被指令la $a1, input_sz.

加载到a1寄存器中

此地址存储的内容无关紧要。 CPU 不会读它。