Arm Cortex-M3 MOV和LDR [英] Arm cortex-m3 mov and ldr

查看:196
本文介绍了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

如果它不能将其编码为一条指令(请注意有一些负向运算,带有程序计数器的数学运算以及它可能会发挥的其他技巧,这些可能是您当时可能没有想到的,或者不知道pc可能无法运行使用),如果不能,则可以将其编码为多条指令,然后立即将其编码为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.

arm架构参考手册中详细记录了mov立即指令的每个指令集的特定限制,您只需购买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天全站免登陆