SPARC - 无移位的位掩码
我正在学习 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
乘以 2 是左移,除以 2 是右移(至少对于无符号数而言)。
如果你想左移 2 位,那就是乘以 4。
因此,例如,如果你有二进制值:
并且你想提取 b3 和 b2,你可以将整个数字与 0xc0 进行 AND 运算,然后除以 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:
and you wanted to extract b3 and b2, you would AND the whole lot with 0xc0 and 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.