SPARC - 无移位的位掩码

发布于 2024-07-13 11:36:27 字数 155 浏览 3 评论 0原文

我正在学习 SPARC 汇编,我必须创建一个从寄存器中提取字段的脚本。 该脚本接受 3 个值,初始编号、字段起始位置、字段长度。
它不能使用任何移位函数,但可以使用乘法和除法。
我目前患有呼吸道病毒,随后正在服用大量药物。 我很难弄清楚从哪里开始。 一些方向将不胜感激。

I'm learning SPARC assembly and I have to create a script that extracts a field from a register. The script accepts 3 values, initial number, field start position, field length.
It can't use any shift functions, but it can use multiply and divide.
I'm currently suffering from a respiratory virus, and am subsequently on a significant amount of drugs. I'm having a lot of difficulty figuring out where to even start on this.
Some direction would be greatly appreciated.

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

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

发布评论

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

评论(1

一曲爱恨情仇 2024-07-20 11:36:27

乘以 2 是左移,除以 2 是右移(至少对于无符号数而言)。

如果你想左移 2 位,那就是乘以 4。

因此,例如,如果你有二进制值:

b15              b0
v                 V
0000 1111 0101 1000

并且你想提取 b3 和 b2,你可以将整个数字与 0xc0 进行 AND 运算,然后除以 4。

0000 1111 0101 1000
0000 0000 0000 1100  <- AND with 0xc0
-------------------
0000 0000 0000 1000
-------------------
0000 0000 0000 0010  <- divide by 4

由于这听起来很像家庭作业(而且我已经很长没有为 SPARC 编写代码了),因此我不会尝试为您提供完整的解决方案 - 这应该足以让您继续下去。

Multiply by 2 is a left-shift and divide by 2 is a right shift (at least for unsigned numbers).

If you want to left shift by 2 bits, that's a multiply by 4.

So, for example, if you have the binary value:

b15              b0
v                 V
0000 1111 0101 1000

and you wanted to extract b3 and b2, you would AND the whole lot with 0xc0 and divide by 4.

0000 1111 0101 1000
0000 0000 0000 1100  <- AND with 0xc0
-------------------
0000 0000 0000 1000
-------------------
0000 0000 0000 0010  <- divide by 4

Since this sounds suspiciously like homework (and I haven't coded for SPARC for a long time), I won't attempt to give you a finished solution - that should be enough to get you going.

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