MIPS - 创建订单的二进制字

发布于 2024-10-27 04:45:08 字数 353 浏览 11 评论 0原文

我有以下 MIPS 语言代码:

lw $s5, -20($s6)

sub $t1, $s5, $t2

addi $t1, $t2, 50

我需要将每个订单转换为其代码

:十进制 b.十六进制 c.在二进制 32 位中

,第一阶 (lw $s5, -20($s6)) 我做了

: 35 | 35 22 | 22 21 | 21 -20

湾。 23 | 23 16 | 16 15 | 15 C

3 个问题:

1)我说得对吗? 2) 32 位二进制的代码是什么? 3)另外2个订单的其他代码是什么?

谢谢 !

I have the following code in MIPS language:

lw $s5, -20($s6)

sub $t1, $s5, $t2

addi $t1, $t2, 50

I need to convert each order to its code:

a. in decimal
b. in hex
c. in binary 32 bits

for the first order (lw $s5, -20($s6)) I did:

a. 35 | 22 | 21 | -20

b. 23 | 16 | 15 | C

3 questions:

1) am I right ?
2) what will be the code for 32 bits binary ?
3) What are the other codes of the other 2 more orders ?

Thanks !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

计㈡愣 2024-11-03 04:45:08

根据操作数和指令类型,有多种编码方案,但它们都是由 32 位组成,前 6 位指定指令操作码(add、lw 等)。

  • 寄存器编码:这些指令仅对寄存器进行操作。前六位是0,接下来是三个五位字段,分别指定第一和第二源寄存器以及目标寄存器。最后还有其他六位指定功能(add、sub 等)

  • 立即编码:这些指令有一个操作数,它是一个内存位置。在六位操作码之后,有两个五位字段用于第一个和第二个寄存器,以及一个十六位字段用于内存位置。

  • 跳转编码:由六位操作码和二十六位跳转目标组成

本文 解释了这些指令编码,并列出了所有二进制操作码/函数编码。一旦确定了二进制形式,只需将其转换为十进制和十六进制即可。

示例:
假设我们想要lw $s5, -20($s6)的编码。这属于立即编码类别,其编码为ooooooss sssttttt iiiiiiiii iiiiiiiii,其中o是操作码,s是第一个寄存器,t是第二个寄存器,i是常量。查看表格,我们发现lw的操作码是100011。指定寄存器的编号就足够了,因此 s 是 00101,t 是 00110。常数(-20)用2的补码表示。 20 为 10100,其 16 位的 2 补码为 1111111111101100lw有一个loadstore语法,其模板是o $t, i ($s),因此寄存器在编码中被交换。因此,lw $s5, -20($s6) 的指令编码为

ooooooss sssttttt iiiiiiii iiiiiiii
10001100 11000101 11111111 11101100

8C C5 FF EC(十六进制)和 140 197 255 236 (十二月)

According to the operands and the type of the instruction, there are several encoding scheme, but all of them are composed by 32 bits and the first six specify the instruction opcode (add, lw etc).

  • Register encoding: these instructions operates only on registers. First six bits are 0, next there are three fields of five bits which specify respectively first and second source register and the destination register. Finally there are other six bits which specify the function (add, sub etc)

  • Immediate encoding: these instruction have an operand which is a memory location. After six bits of opcode there are two fields of five bits for the first and second register, and a field of sixteen bits for the memory location.

  • Jump Encoding: they're composed by six bits of opcode and twenty-six bits of jump destination

This article explains these instructions encoding and has a list of all opcodes / function encoding in binary. Once you have determined the binary form simply convert it to decimal and hexadecimal.

EXAMPLE:
Suppose we want the encoding of lw $s5, -20($s6). This falls into immediate encoding category, whose encoding is ooooooss sssttttt iiiiiiii iiiiiiii, with o being the opcode, s the first register, t the second register and i the constant. Looking on the table we find the opcode for lw is 100011. Specifying the register's number is enough, so s is 00101 and t is 00110. The constant (-20) is represented by 2s complement. With 20 being 10100, its 2s complement on 16 bit is 1111111111101100. lw has a loadstore syntax, which template is o $t, i ($s), so the registers are swapped in the encoding. Therefore the instruction encoding for lw $s5, -20($s6) is

ooooooss sssttttt iiiiiiii iiiiiiii
10001100 11000101 11111111 11101100

or 8C C5 FF EC (hex) and 140 197 255 236 (dec)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文