[ARM-assembly]-汇编示例:c语言翻译成汇编

272 篇文章 415 订阅

快速链接:
.
👉👉👉 个人博客笔记导读目录(全部) 👈👈👈

在这里插入图片描述

示例1:

int func_test(uint32_t a, uint32_t b, uint32_t *s)
{
	*s = a + b;
	return 0;
}

00000000002047a0 <func_test>:
  2047a0:	0b010000 	add	w0, w0, w1
  2047a4:	b9000040 	str	w0, [x2]
  2047a8:	52800000 	mov	w0, #0x0                   	// #0
  2047ac:	d65f03c0 	ret

示例2

int func_memcpy(void *a, void *b, uint32_t len)
{
	memcpy(a,b,len);
	return 0;
}

int func_test(uint32_t integer1, uint32_t integer2, uint32_t *p_integer)
{
	char a[128];
	*p_integer = integer1 + integer2;

	func_memcpy(a,"testtesttesttesttesttest",*p_integer);
	return 0;
}
数据段中的:"testtesttesttesttesttest"
  215430:	6f697372 7325206e 6574000a 65747473     rsion %s..testte
  215440:	65747473 65747473 65747473 65747473     sttesttesttestte
  215450:	76007473 69737265 25206e6f 64252c64     st.version %d,%d

00000000002047a0 <func_test>:
  2047a0:	a9b77bfd 	stp	x29, x30, [sp,#-144]!
  2047a4:	0b010000 	add	w0, w0, w1
  2047a8:	b0000081 	adrp	x1, 215000 <build_message+0x2a0>
  2047ac:	910003fd 	mov	x29, sp
  2047b0:	b9000040 	str	w0, [x2]
  2047b4:	9110e821 	add	x1, x1, #0x43a
  2047b8:	2a0003e2 	mov	w2, w0
  2047bc:	910043a0 	add	x0, x29, #0x10
  2047c0:	94003d7d 	bl	213db4 <memcpy>
  2047c4:	52800000 	mov	w0, #0x0                   	// #0
  2047c8:	a8c97bfd 	ldp	x29, x30, [sp],#144
  2047cc:	d65f03c0 	ret

由此看来,这是一个递减的栈.
(1)
stp x29, x30, [sp,#-144]! //sp=sp-144后,将x29和x30拷贝到sp中,即:
0到-128是数组变量a,-129到-144是 x29和x30(lr)。 这里其实就是保存x29和x30
(2)
add x0, x29, #0x10 //x29是当前的栈地址(sp),sp+0x10正好就是数组a的地址,这句就是将数组a的地址拷贝到x0中
(3)ldp x29, x30, [sp],#144 从sp处拷贝两个double-world到x29和x30,这里其实就是恢复x29和x30。 拷贝之后,再sp=sp+144


2) Who uses ARM? Currently ARM CPU is licensed and produced by more than 100 companies and is the dominant CPU chip in both cell phones and tablets. Given its RISC architecture and powerful 32-bit instructions set, it can be used for both 8-bit and 32-bit embedded products. The ARM corp. has already defined the 64-bit instruction extension and for that reason many Laptop and Server manufactures are planning to introduce ARM-based Laptop and Servers. 3) Who will use our textbook? The primary audience of our textbook on ARM (ARM Assembly Language Programming & Architecture by Mazidi & Naimi) is undergraduate engineering students in Electrical and Computer Engineering departments. It can also be used by practicing engineers who need to move away from 8- and 16-bit legacy chips such as the 8051, AVR, PIC and HCS08/12 family of microcontrollers to ARM. Designers of the x86-based systems wanting to design ARM-based products can also benefit from this textbook. Table of Contents Chapter 1: The History of ARM and Microcontrollers Chapter 2: ARM Architecture and Assembly Language Programming Chapter 3: Arithmetic and Logic Instructions and Programs Chapter 4: Branch, Call, and Looping in ARM Chapter 5: Signed Numbers and IEEE 754 Floating Point Chapter 6: ARM Memory Map, Memory Access, and Stack Chapter 7: ARM Pipeline and CPU Evolution Appendix A: ARM Cortex-M3 Instruction Description Appendix B: ARM Assembler Directives Appendix C: Macros Appendix D: Flowcharts and Pseudocode Appendix E: Passing Arguments into Functions Appendix F: ASCII Codes
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

代码改变世界ctw

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值