对有符号/无符号加载和存储指令(MIPS)的说明 [英] Clarifications on signed/unsigned load and store instructions (MIPS)

查看:1073
本文介绍了对有符号/无符号加载和存储指令(MIPS)的说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即使借助Google和一本教科书,我似乎也无法掌握这些内容的概念.

遵循格式(操作码,rs,rt,偏移量)...

  • 是否在将偏移量添加到地址值之前对其进行符号扩展?还是在扩展之前添加?
  • 对于 lb lbu ,有什么区别?它是否也遵循MIPS算术定义,即无符号"仅表示它不会报告溢出?
  • 为什么 lw 没有未签名的版本?甚至商店的指示都没有...

解决方案

对于lblbu,有什么区别?

加载字节"指令lblbu将单个字节加载到32位寄存器的最右字节中.如何设置高24位? unsigned 操作会将它们设置为零;签名的操作将签名扩展已加载的字节.

例如,假设您从内存中读取了字节0xFF. lbu会将这个值0扩展到0x000000FF并将其解释为255,而lb会将其符号扩展到0xFFFFFFFF的解释为-1.

为什么lw没有未签名的版本?甚至商店的指示都没有...

另一方面,加载字"指令(lw)将32位量加载到32位寄存器中,因此没有歧义,也不需要特殊的带符号版本. /p>

如果您存储的少于一个完整的32位字,则除了丢弃它们(忽略它们)之外,您无法使用寄存器中的多余位.

它是否也遵循MIPS算术定义,即无符号"只是表示它不会报告溢出?

我认为此约定仅适用于加减指令.对于其他指令,带符号/无符号表示是否将执行符号扩展.

在将偏移量添加到地址值之前,您是否先对其进行扩展?还是在扩展之前添加?

如果偏移量是符号扩展的,则只有在将其添加到基址之前才有意义.我认为,对二进制补数算法的回顾将使这一点变得清楚.

I can't seem to grasp the concept on these stuff, even with the help of Google and a textbook in my hand.

Following the format (opcode, rs, rt, offset)...

  • Do you sign extend the offset before adding it to the value of the address? Or add before extending?
  • In the case of lb and lbu, what's the difference? Does it also follow the MIPS arithmetic definition that 'unsigned' just means it won't report an overflow?
  • Why doesn't lw have an unsigned version? Even the store instructions don't have one...

解决方案

In the case of lb and lbu, what's the difference?

The "load byte" instructions lb and lbu load a single byte into the right-most byte of a 32-bit register. How do you set the upper 24 bits? The unsigned operation will set them to zero; the signed operation will sign-extend the loaded byte.

For example, suppose you read the byte 0xFF from memory. lbu will 0-extend this value to 0x000000FF and interpret it as 255, while lb will sign-extend it to 0xFFFFFFFF, which is interpreted as -1.

Why doesn't lw have an unsigned version? Even the store instructions don't have one...

The "load word" instruction (lw), on the other hand, loads a 32-bit quantity into a 32-bit register, so there is no ambiguity, and no need to have a special signed version.

If you are storing less than a full 32-bit word, there is nothing you can do with the extra bits in the register except throw them away (ignore them).

Does it also follow the MIPS arithmetic definition that 'unsigned' just means it won't report an overflow?

I think this convention is only for the add and subtract instructions. For the other instructions, signed/unsigned indicates whether sign-extension will be performed.

Do you sign extend the offset before adding it to the value of the address? Or add before extending?

If an offset is sign-extended, it only makes sense to do it before adding it to the base address. I think a review of two's complement arithmetic will make this clear.

这篇关于对有符号/无符号加载和存储指令(MIPS)的说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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