创建新的 MIPS 指令

发布于 2025-01-19 13:19:31 字数 462 浏览 3 评论 0原文

我在理解一个问题时遇到一些问题。考虑提议的名为 rpt 的新指令。该指令将循环的条件检查和计数器递减合并到一条指令中。例如,rpt $s0,loop将执行以下操作:

if (x29 > 0) {
   x29 = x29 − 1;
   goto loop
}
  1. 如果要在MIPS指令集中实现该指令,最合适的指令格式是什么? 我想 J 格式可以吗? (即 6 位操作和 26 位地址)由于指令必须跳转到循环,因此您需要一个大字段来容纳地址。但是有一个参数$s0,我很困惑它的用途以及x29

  2. 执行相同操作的 MIPS 指令的最短序列是什么?

有人能给我清楚地解释一下这个 rpt 指令和循环的作用并回答这两个问题吗?我很乐意感激,谢谢。

I'm having some problems understanding a question. Consider a proposed new instruction named rpt. This instruction combines a loop’s condition check and counter decrement into a single instruction. For example, rpt $s0, loop would do the following:

if (x29 > 0) {
   x29 = x29 − 1;
   goto loop
}
  1. If this instruction were to be implemented in the MIPS instruction set, what is the most appropriate instruction format?
    I suppose the J-format would do? (that is, 6 bits of op & 26 bits of address) Since the instruction would have to jump to loop, you would need a large field to fit the address. However there is a parameter $s0, I'm very confused what it is used for and also the x29.

  2. What is the shortest sequence of MIPS instructions that performs the same operation?

Can someone give me a clear explanation of what this rpt instruction and loop does and answer the two questions? I would gladly appreciate it, thank you.

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

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

发布评论

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

评论(1

玻璃人 2025-01-26 13:19:31

这是您必须解决的一个问题:

汇编示例使用 $s0,它是寄存器 16。但是操作的描述使用x29,它可以引用堆栈指针寄存器$29,但肯定不是$s0。所以,这两者不匹配,除非你让它们匹配,否则你会遇到麻烦。

相比之下,操作描述中loop的使用似乎与汇编形式中标签loop的使用相匹配。

如果匹配的话会是什么样子:

A:

rpt $s0, loop
---
if ($s0 > 0) {
   $s0 = $s0 − 1;
   goto loop
}

这是匹配的,因为 $s0loop 都是汇编形式和操作描述。

通过这种方式解决,J 类型指令将无法同时对寄存器和指令目标进行编码。

否则B:

rpt loop
---
if (x29 > 0) {
   x29 = x29 − 1;
   goto loop
}

这匹配,因为在操作描述中使用了x29;它只是隐含在汇编语法中——即它被硬编码为29,并且汇编程序员无法指定不同的寄存器。

以这种方式解决,J型指令可能是适用的,因为仅需要对指令目标进行编码。


更令人困惑的是,xN 寄存器表示法不是 MIPS 的典型表示法,而是 ARM 和 RISC V 处理器的典型表示法。 MIPS 程序集将使用 $29 表示法。所以,那篇文章似乎断章取义。

我怀疑有人把这个问题从 RISC V(其中 x29,又名 t4,是一个合理使用的寄存器)转换为 MIPS,做得不好/不完整。

建议你把这个问题反馈给你的导师并澄清。

Here's a problem you'll have to resolve:

The assembly example uses $s0, which is register 16.  But the description of the operation uses x29, which could refer to the stack pointer register, $29, but certainly not $s0.  So, these two don't match up and until you get them to match up, you'll have troubles.

By contrast, the usage of loop in the operational description seems to match up with the usage of label loop in the assembly form.

How it would look if it matched up:

A:

rpt $s0, loop
---
if ($s0 > 0) {
   $s0 = $s0 − 1;
   goto loop
}

This matches up because $s0 and loop are in both the assembly form and the operational description.

Resolving this way, a J-Type instruction would not accommodate encoding both the register and instruction target.

or else B:

rpt loop
---
if (x29 > 0) {
   x29 = x29 − 1;
   goto loop
}

This matches up because x29 is used in the operational description; it is simply implied in the assembly syntax — i.e it is hard coded to 29 and the assembly programmer cannot specify a different register.

Resolving this way, a J-Type instruction might be applicable, since only an instruction target need be encoded.


Further confusing things is that the xN register notation is not typical of MIPS, but of ARM and RISC V processors.  MIPS assembly would use the $29 notation instead.  So, that piece seems out of context.

My suspicion is that someone did an bad/incomplete job of translating this problem from RISC V (where x29, aka t4, is a reasonable register to used) to MIPS.

Suggest you take this back to your instructors and clarify.

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