为什么是 `addi $reg, $0, N` 而不是 `li $reg N`? [英] Why `addi $reg, $0, N` instead of `li $reg N`?

查看:71
本文介绍了为什么是 `addi $reg, $0, N` 而不是 `li $reg N`?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过网上找到的资源自己学习 MIPS*,看到很多人在做 addi $reg, $0, N 来存储数值 N一个寄存器 $reg,我想知道为什么当 li $reg N 可以这样做时它如此普遍.

I'm learning MIPS by myself with sources found online* and see a lot of people doing addi $reg, $0, N to store a numerical value N inside a register $reg, and am wondering why is this so ubiquitous when li $reg N would do.

我错过了什么?

*(所以不要对我所学的内容进行详尽而易于理解的解释)

*(so don't have exhaustive while accessible explanations of what I learn)

推荐答案

Assembler 具有:

Assembler has:

  • 指令——.text.data.align 2、其他
  • 标签——main:
  • 常规指令——addi $a0, $0, 1beq $a0, $a1, label
  • 伪指令——li $a0, 1​​bge $a0, $a1, label
  • 存储声明——.word 100(有些也称这些指令)
  • directives — .text, .data, .align 2, others
  • labels — main:
  • regular instructions — addi $a0, $0, 1 and beq $a0, $a1, label
  • pseudo instructions — li $a0, 1 and bge $a0, $a1, label
  • storage declarations — .word 100 (some call these directives as well)

.text &.data 在代码和数据部分之间切换,后续汇编行打算用于.

.text & .data switch between code and data sections that subsequent lines of assembly intended for.

常规指令提供与硬件机器代码语言的直接对应.

The regular instructions offer direct correspondence with the hardware machine code language.

伪指令是硬件并没有直接拥有的指令,但可以通过一些替换来完成,这通常是扩展另一条指令的参数数量(例如,将 $0 添加到参数列表中),有时甚至有不止一个机器代码指令.liaddi ... $0 ... 更容易阅读,所以它是首选——除非你的老师已经指示你避免使用伪指令.

Pseudo instructions are instructions that the hardware doesn't really have directly, but can be accomplished with some substitution, which is usually expansion in the number of arguments to another instruction (e.g. adding $0 to the list of arguments), and sometimes even having more than one machine code instructions.  li is easier to read than addi ... $0 ..., so it is preferred — unless your educator has instructed you to avoid pseudo instructions.

如果您使用的是 MARS 模拟器,您会发现它的帮助菜单详细介绍了这些不同类别的成员.

If you're using the MARS simulator, you'll find that its help menu details the members of these different categories.

当您编写伪指令时,您可以看到汇编器将它们翻译成哪些真正的机器代码指令.

When you write a pseudo instructions, you can see what real machine code instruction(s) the assembler translated them into.

就像任何语言一样,汇编语言提供常量数据,如字符串文字、浮点常量等.它还支持全局/静态变量.这些都是使用存储声明完成的.

Just like any language, assembly language provides for constant data, like string literals, floating point constants, etc..  It also supports global/static variables.  These are all done using the storage declarations.

这篇关于为什么是 `addi $reg, $0, N` 而不是 `li $reg N`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆