这些说明有什么作用

发布于 2024-08-04 15:46:59 字数 388 浏览 7 评论 0原文

我正在开发 msp430 指令集的模拟器。 gnu 汇编器将允许您对如下指令进行编码:

fc0a: 12 10 00 02 rrc &0x0200       
fc0e: 22 11       rra #4        
fc10: 23 52       add #4,#2

我的猜测是 rrc &0x0200 将从地址 0x0200 获取执行旋转然后将答案写回地址 0x0200,对吗?但是 rra #4 会做什么呢?我假设源是立即的 4 但操作后有目的地吗? add #4,#2 组装成您期望的内容(如 2b10,source = r2,ad = 1b0,dest = r3),但 binutils 反汇编程序不知道如何处理该指令。

这些指令有效吗?

I am working on a simulator for the msp430 instruction set. gnu assembler will let you encode instructions like these:

fc0a: 12 10 00 02 rrc &0x0200       
fc0e: 22 11       rra #4        
fc10: 23 52       add #4,#2

My guess is that rrc &0x0200 will fetch from address 0x0200 perform the rotate then write the answer back to address 0x0200, correct? But what would an rra #4 do? The source would be an immediate 4 I assume but is there a destination after the operation? The add #4,#2 assembled into what you would expect (as 2b10, source = r2, ad = 1b0, dest = r3), the binutils disassembler though did not know what to do with that instruction.

Are these valid instructions?

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

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

发布评论

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

评论(3

以往的大感动 2024-08-11 15:46:59

尽管似乎没有任何关于此效果的明确的在线参考,但我倾向于同意OP的观点,即显示的两条指令(以及其他几条指令)可能无效,即使它们符合数据表中定义的格式。

换句话说,并非组成指令字的各个部分的所有可能组合都是有效的。特别是许多使用立即寻址模式的单操作数指令和许多对目标具有立即寻址模式的双操作数指令在语义上可能不可行。

文档中对此效果只有一些提示,例如,在《用户指南》第 3.3.7 节(关于立即寻址模式)中,注释指出“仅对源操作数有效。”(顺便说一句,这适用于立即寻址模式的所有情况,而不仅仅是 R2 或 R3 常量生成技巧允许的速记情况。)

事实上,反汇编程序不知道如何处理此类代码这也是另一个提示(尽管......一些反汇编程序很容易被绊倒......)。

为了便于记录,我在下面收集了一些有关 MSP430 的有用参考资料:

Although there doesn't appears to be any definitive online reference to this effect, I tend to agree with the OP that the two instructions shown (and several others) are likely not valid, even though they conform to the format defined in the data sheets.

In other words, not all possible combinations of the various parts that make up a instruction word are valid. In particular many single operand instructions that use the immediate addressing mode, and many double operand instructions that have an immediate addressing mode for the destination are probably not semantically viable.

There are only a few hints to this effect in the documentation, for example, in the User's Guide, section 3.3.7 (on the immediate addressing mode), a comment indicates "Valid only for a source operand." (And, BTW, this is for all cases of immediate addressing mode, not just the short-hand cases allowed by the R2 or R3 constant generation trick.)

The fact that the disassembler doesn't know what to do with such codes is also another hint (although... some disassemblers get tripped easily...).

For sake of documentation, I gathered below a few useful references for the MSP430:

感性不性感 2024-08-11 15:46:59

在当前用户指南的第 3.4.4.2 节中,建议不要在命令 RRA 的目标字段中使用立即模式 (#N),因为它会导致“不可预测的程序操作”。

In the current users guide, in section 3.4.4.2, it recommends not using the immediate mode (#N) in the destination field for the command RRA as it results in "unpredictable program operation."

遥远的她 2024-08-11 15:46:59

他们有可能是。查看维基百科上的指令集,操作码对寄存器和各种选项进行编码。所以这不是一个简单的映射。看起来你得到的输出是小端字节序,所以:

fc0a: 12 10 00 02 rrc &0x0200  

对应于指令 1012,其二进制为 0001 0000 0001 0010。

分解如下:

6 bits: 0001 00 - fixed; defines the instruction family
3 bits: 00 0    - instruction (RRC)
1 bit : 0       - byte or word parameter (0 = 16 bit parameter; 1 = 8 bit)
2 bits: 01      - addressing mode (01 = indexed;)
4 bits: 0010    - register

所以在这种情况下,右旋转发生在寄存器 2 中距地址 &0200 偏移的值。

您需要以类似的方式分解其他说明才能完全理解。对于 ADD 指令,源和目标寄存器/地址都编码在
5223指令。

It's possible they are. Looking at the instruction set on Wikipedia, the opcodes encode the register and various options. So it's not a simple mapping. It looks like the output you've got is little-endian, so this:

fc0a: 12 10 00 02 rrc &0x0200  

corresponds to the instruction 1012, which in binary is 0001 0000 0001 0010.

This breaks down as follows:

6 bits: 0001 00 - fixed; defines the instruction family
3 bits: 00 0    - instruction (RRC)
1 bit : 0       - byte or word parameter (0 = 16 bit parameter; 1 = 8 bit)
2 bits: 01      - addressing mode (01 = indexed;)
4 bits: 0010    - register

So in this case a rotate-right is occuring on the value at the offset in register 2 from address &0200.

You'd need to break the other instructions down in a similar way to fully understand. For the ADD instruction, both the source and destination registers/addresses are encoded in the
5223 instruction.

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