什么是“关系"?在阿迪和苏比之间? [英] What is the "relationship" between addi and subi?

查看:151
本文介绍了什么是“关系"?在阿迪和苏比之间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该回答这个问题.经过一番研究,它说add和sub具有相同的操作码,仅在功能领域有所不同.这是答案还是其他?

I'm supposed to answer this question. After some research it says that add and sub have the same opcode and differ only in the functional field. Is this the answer or something else?

在Nios II CPU手册中可用:

It's available in the Nios II CPU manual:

subi
subtract immediate
Operation: rB ← rA – σ (IMMED)
Assembler Syntax: subi rB, rA, IMMED
Example: subi r8, r8, 4
Description: Sign-extends the immediate value IMMED to 32 bits, subtracts it from the value of rA and then
            stores the result in rB.
Usage: The maximum allowed value of IMMED is 32768. The minimum allowed value is
–32767.
Pseudo-instruction:
© March 2009
subi is implemented as addi rB, rA, -IMMED

推荐答案

我不知道MIPS甚至都具有正确的subi指令(尽管某些环境可能为其实现了宏).

I'm unaware that MIPS even has a proper subi instruction (though some environments may implement a macro for it).

由于要减去立即值,因此可以将其取反值提供给addi指令:

Since you're subtracting an immediate value, you can just provide the negation of it to the addi instruction:

addi $r1, $r2, -42     ; equivalent to subi $r1, $r2, 42

立即数是一个二进制补码值,这意味着它完全可以成为负数,并且二进制补数的工作方式意味着您可以以 unsigned 的方式添加一个负数,从而得到与减法相同的结果(因为您回绕).

The immediate operand is a two's complement value which means it's perfectly capable of being a negative number and the way that two's complement works means that you can add a negative number in an unsigned manner and that gives the same result as subtracting (since you wrap around).

例如,在16位二进制补码中的-42是无符号值65494.当您在65536处添加5065494换行时,最终得到:

For example, -42 in 16-bit two's complement is the unsigned value 65494. When you add 50 and 65494 wrapping around at 65536, you end up with:

     50
+ 65494 (ie, -42)
  -----
  65544 (overflow, so
- 65536  we wrap at 64K)
  -----
      8 (identical to "50 - 42")

这篇关于什么是“关系"?在阿迪和苏比之间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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