ndk内联汇编的使用之arm指令学习和调试

原创
2016/06/06 19:31
阅读数 171
#include <stdio.h>


int my_thumb_wjh(int dummy)
{
	__asm__(
	"mov r0,#1 \t\n"	
	"mov r1,#2 \t\n"
	"add r0,r0,r1 \t\n"
	"bx lr"
		
	);
	return dummy;
	
}
int my_thumb(int dummy)
{

	__asm__(

	"mov r0,#13 \t\n"

	"mov r1,#2 \t\n"

	"add r0,r0,r1 \t\n"

	"bx lr"
		
		);
	return dummy;

}
int my_thumb2(int dummy)
{
	__asm(
	"mov r0,#0x1\t\n"
	"ldr r0,__start\t\n"
	"adr r0,__start\t\n"
	"ldr r0,__start\t\n"		
	"__start:\t\n"
	"nop\t\n"
		);
	return dummy;
}
int data_function()
{
	printf("data_function run\n");
	return 1024;
}

static int my_arm(int dummy)
{
		__asm__(

	"mov r0,#13 \t\n"

	"mov r1,#2 \t\n"

	"add r0,r0,r1 \t\n"
	"mov r3,#5 \t\n"
	"sub r0,r0,r3 \t\n"
	"mov r3,#9 \t\n"
	"mul r0,r0,r3 \t\n"
	"bx lr"	
		);	
	return dummy;
}
void test()
{
	__asm__(	
	"bl data_function \t\n"
		);
	
	printf("test run\n");
	
}


//http://blog.csdn.net/zhangmiaoping23/article/details/44782843
//ndk内联汇编的使用之arm指令学习和调试
int main(int argc, char **argv)
{
	
	int n = my_thumb(12);
	printf("result=%d\n", n);
	
	int result = my_thumb2(12);
	printf("result=%d\n", result);
	
	int result_my_arm = my_arm(12);
	printf("result_my_arm=%d\n", result_my_arm);
	
	test();
	
	printf("Hello, World!\n");	//Set a breakpoint here or press F10 to step into.
	return 0;
}

 


LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE    := arm_demo
#VisualGDBAndroid: AutoUpdateSourcesInNextLine
LOCAL_SRC_FILES := arm_demo.c
LOCAL_C_INCLUDES :=
LOCAL_STATIC_LIBRARIES :=
LOCAL_SHARED_LIBRARIES :=
LOCAL_LDLIBS :=
LOCAL_CFLAGS :=
LOCAL_CPPFLAGS :=
LOCAL_LDFLAGS :=
COMMON_SRC_FILES := $(LOCAL_SRC_FILES)
include $(BUILD_EXECUTABLE)

 

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部