Arm cortex-m3 mov 和 ldr [英] Arm cortex-m3 mov and ldr

查看:26
本文介绍了Arm cortex-m3 mov 和 ldr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白为什么我不能写 mov r1, #5000.为什么我必须使用 ldr 代替?R1 是 32 位寄存器,范围为 5000.我发现我可以mov r1, #255 但不能mov r1, #256.对我来说似乎很奇怪.

I don't get why I can't write mov r1, #5000. Why I have to use ldr instead? R1 is 32 bit register and 5000 fits in range. And as I discovered I can mov r1, #255 but can't mov r1, #256. It seems weird for me.

推荐答案

阅读关于指令的文档,在这种情况下,指令是固定长度的,因此您没有空间容纳指令信息(操作码等)和16 或 32 位指令中的 32 位立即数,这是不可能的,因此需要对立即数进行一些限制.例如,对于 x86,它是可变指令长度,因此它们可以有长指令,但很容易争辩说,执行与 pc 相关的加载或相同大小的一些固定长度指令对流水线没有显着的额外成本.所以六个六个.mips 固定指令长度移动立即解决方案有其优点和缺点,对于每个 arm 指令集,每个都有自己的优点和缺点的解决方案.

read the documentation on the instructions, in this context the instructions are fixed length, so you dont have room for both the instruction information (opcode, etc) and a 32 bit immediate in the 16 or 32 bit instruciton, not possible so some limitation on the immediate is required. With x86 for example it is variable instruction length so they can have long instructions, but it is easy to argue that doing a pc-relative load or a few fixed length instructions of the same size have no significant extra cost with a pipeline. so six of one half dozen of another. The mips fixed instruction length move immediate solution has its strengths and weakness and for each of the arm instruction sets each has its own solution with strengths and weaknesses.

对于汇编器(当然是 gcc,可能是武器工具链、keil 等)有一个捷径可以做,汇编器会选择更简单的路径

for arm the assemblers (certainly gcc, probably arms toolchain, keil, etc) there is a shortcut you can do and the assembler will choose the simpler path

ldr r1,=immediate

如果它不能将它编码成一条指令(请注意,有一些负面的移动,程序计数器的数学运算以及它可以发挥的其他技巧,您当时可能没有想到或不知道电脑可能无法使用),如果不能,则可以将其编码为多条指令 mov 立即数然后是 orr,或将其编码为 pc 相对负载.

if it cant encode it into a single instruction (note there are some move negative, math with the program counter and other tricks it can play that you might not be thinking of at the time or not knowing the pc might not be able to use), if it cannot then it may encode it as multiple instructions mov immediate then an orr, or encode it as a pc relative load.

每个指令集 mov 立即的具体限制在 arm 架构参考手册中有详细记录,您只需获取 armv7,它就具有该架构版本和先前架构版本的所有编码.有了这些知识,您应该能够在汇编程序告诉您之前确定自己是否可以使用 mov.

The specific limitations for each instruction sets mov immediate is well documented in the arm architectural reference manuals, you can just get the armv7 one and it has all the encodings for that and prior architecture versions. with that knowledge you should be able to determine yourself whether or not the mov will work before having the assembler tell you.

这篇关于Arm cortex-m3 mov 和 ldr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆