Intel x86 到 ARM 程序集转换 [英] Intel x86 to ARM assembly conversion

查看:53
本文介绍了Intel x86 到 ARM 程序集转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在学习ARM汇编语言;

I am currently learning ARM assembly language;

为此,我正在尝试将一些 x86 代码(AT&T 语法) 转换为 ARM 汇编 (Intel 语法) 代码.

To do so, I am trying to convert some x86 code (AT&T Syntax) to ARM assembly (Intel Syntax) code.

__asm__("movl $0x0804c000, %eax;");

__asm__("mov R0,#0x0804c000");

从这个 document,我了解到在 x86 中的 Chunk 1堆结构从 0x0804c000 开始.但是当我尝试在 arm 中做同样的事情时,我收到以下错误:

From this document, I learn that in x86 the Chunk 1 of the heap structure starts from 0x0804c000. But I when I try do the same in arm, I get the following error:

/tmp/ccfNZp9F.s:174: Error: invalid constant (804c000) after fixup

我假设问题是 ARM 只能加载 32bit 说明.

I am assuming the problem is that ARM can only load 32bit instructions.

Question 1: Any idea what would be the first chunk in case of ARM processors?


Question 2:

从我之前的问题,我知道了内存间接寻址的工作原理.

From my previous question, I know how memory indirect addressing works.

下面写的片段是否做同样的工作?

Are the snippets written below doing the same job?

movl (%eax), %ebx

LDR R0,[R1]

我正在使用 ARMv7 Processor rev 4 (v7l)

推荐答案

问题一解答

ARM 上的 MOV 指令只有 12 位可用于立即数,而这些位是这样使用的:8 位用于值,4 位用于指定向右的旋转次数(旋转次数相乘)2,以增加范围).

The MOV instruction on ARM only has 12 bits available for an immediate value, and those bits are used this way: 8 bits for value, and 4 bits to specify the number of rotations to the right (the number of rotations is multiplied by 2, to increase the range).

这意味着该指令只能使用有限数量的值.它们是:

This means that only a limited number of values can be used with that instruction. They are:

  • 0-255
  • 256、260、264、...、1020
  • 1024、1040、1056、...、4080

等等.您收到该错误是因为无法使用 8 位 + 旋转创建常量.您可以按照以下指令将该值加载到寄存器中:

And so on. You are getting that error because your constant can't be created using the 8 bits + rotations. You can load that value onto the register following instruction:

LDR r0, =0x0804c000

请注意,这是一条伪指令.汇编器基本上会将该常量放在代码中的某个位置,并将其作为内存位置加载,并与 PC(程序计数器)有一些偏移.

Notice that this is a pseudo-instruction though. The assembler will basically put that constant somewhere in your code and load it as a memory location with some offset to the PC (program counter).

问题 2 的答案

是的,这些说明是等效的.

Yes those instructions are equivalent.

这篇关于Intel x86 到 ARM 程序集转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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