ARM Assembler VS GNU Assembler

本人引用自:http://www.wretch.cc/blog/trackback.php?blog_id=DreamYeh&article_id=888788

这几天要把我写好的ARM code 移植到Android 上,遇到了一些问题-简单来说「在使用RVDS 开发出来的ARM code ,是无法直接给Android 使用的!」,自行解决后,仍然好奇根本原因,查资料结果,整理如本文件。

 

注意这个问题,在我们之后专注开发ARM code 过程中,一定会遇到!希望大家可以看一下这份文件

 

简单来说一个结论:

 

在windows下,使用RVDS 等工具,底层都会呼叫ARMCC ,这是ARM 公司提供的ARM 汇编器,语法指令完全符合ARM 指令集

 

但是你实际在编译时候呢?使用的是arm-linux-gcc ,基于Linux 的ARM 交叉编译器,使用的是GNU 的汇编方式,除了指令集与ARM 指令相容(不相容就无法移植了:-) ),语法环境和很多虚拟指令,都和ARM 的标准不一样,比如= 和EQU ,import和.globle 等等。

因此当你要Release  code 给Andorid 的负责成员时候,就要注意这些格式上的转换!

 

我在这边把要注意的事情整理成文件,给大家参考

1. Introduction

In ADS and SDT environment, arm asm is usually used, it can be compiled by arm compiler, armcc.

While for linux programming environment, we use GNU GCC compiler that supports GNU asm (GAS).

These two kinds of asm compiler has different syntax, so it's important to replant one kind of code to another.

In this document, the most important things that should be kept in mind during the replanting stage is put.

2.     replanting

2.1     Replanting of . s file

2.1.1     Comment

In arm asm, “;” is used to comment off a line.

In GAS, we use “@”, “#” or “//” can be used to comment off a line, and “/* */” can be used to comment off more than one line.

The example below show the difference,

For ADS environment

;

; ------------------------------------------------- --------------------------

;Static Global Data section variables

;------------------------------------------------- --------------------------

;

; -------------------------- NONE ---------------------- ---------------------

For GAS environment

@

/* ------------------------------------------------ ---------------------------

@Static Global Data section variables

@------------------------------------------------- --------------------------

*/

// -------------------------- NONE --------------------- ----------------------

2.1.2     Operator

(1). Define a constant:

ADS: @TIMER1_CTRL EQU 0x0A800008

GAS: .equ TIMER1_CTRL, 0x0A800008

(2). Define a label or symbal:

ADS: LABEL_ONE

GAS: LABEL_ONE:

(3).

ADS: DCD

GAS: .long

(4). Define a function:

ADS: myfunc FUNCTION

XXXX  

XXXX

ENDFUNC

Or

myfunc PROC

XXXX  

XXXX

ENDP

GAS: myfunc:

XXXX  

XXXX

(5). Define a global function or variable

ADS: @EXPORT SspSipStopTimer1

GAS: .global SspSipStopTimer1

(6).

ADS: DCD

GAS: .long

(7). Code section

ADS: AREA WORD, CODE, READONLY

          XXXX

          XXXX

          END

GAS: .text

          XXXX

          XXXX

          .end

(8). Data section

ADS: AREA BLOCK, DATA, READWRITE

          XXXX

          XXXX

          END

GAS: .data

          XXXX

          XXXX

          .end

(9).

ADS: :OR:

GAS: |

(10).

ADS: :SHL:

GAS: <<

(11).

ADS: :SHR:

GAS: >>

(12).

ADS: CODE32:

GAS: .arm

(13).

ADS: CODE16:

GAS: .thumb

(14).

ADS: %:

GAS: .fill

(15).

ADS: LTORG:

GAS: .ltorg

(16).

ADS: INCLUDE:

GAS: .include

(17).

ADS: IF:DEF:

GAS: .IFDEF

(18).

ADS: ELSE

GAS: .ELSE

(19).

ADS: ENDIF

GAS: .ENDIF

(20).

ADS: &

你可能感兴趣的:(汇编)