Sunday, September 25, 2011

Include into assembler files .h files with definitions

This very general question how to incorporate C and Assembler. Bcoz sometimes you have many C sources and headers and you need rewrite something on assembler. Everybody knows about inline assembler in gcc. But not many knows that you can write into assembler and include some of required .h files. Linux kernel has some examples, but they not easy to look. I found some good explanation on ARM site [1] and adopt it for gcc




; ----- ex.s -----
; arm-none-linux-gnueabi-gcc -E ex.S > p_ex.s

#include "my_header.h"

AREA Example, CODE, READONLY

start
MOV r0, #ONE_CONSTANT
ADD r0, r0, r1
MOV pc,lr

END
--- end ex.s ---

/* ------- my_header.h -------- */
#define ONE_CONSTANT 1
/* ------- my_header.h -------- */

now preprocess ex.S file with gcc from Codesourcery ARM cross toolkit

arm-none-linux-gnueabi-gcc -E ex.S > p_ex.s

and that we have???

# 1 "ex.S"
# 1 ""
# 1 ""
# 1 "ex.S"
; ----- ex.s -----
; arm-none-1 -gnueabi-gcc -E ex.S > p_ex.s

# 1 "my_header.h" 1
# 5 "ex.S" 2

AREA Example, CODE, READONLY

start
MOV r0, #1
ADD r0, r0, r1
MOV pc,lr

END
--- end ex.s ---

[1] http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/ka3529.html

No comments:

Post a Comment