MIPS - 创建订单的二进制字
我有以下 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据操作数和指令类型,有多种编码方案,但它们都是由 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 补码为1111111111101100
。lw
有一个loadstore语法,其模板是o $t, i ($s)
,因此寄存器在编码中被交换。因此,lw $s5, -20($s6)
的指令编码为或
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 isooooooss 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 forlw
is100011
. Specifying the register's number is enough, so s is00101
and t is00110
. The constant (-20) is represented by 2s complement. With 20 being10100
, its 2s complement on 16 bit is1111111111101100
.lw
has a loadstore syntax, which template iso $t, i ($s)
, so the registers are swapped in the encoding. Therefore the instruction encoding forlw $s5, -20($s6)
isor
8C C5 FF EC
(hex) and140 197 255 236
(dec)