c语言中变量对应汇编立即数寻址,指针对应寄存器寻址,指针的指针对应寄存器间接寻址。用下面这段代码作为例子:
test.c:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
int a = 5;
int *p1 = &a;
int **p2 = &p1;
return 0;
}
arm-cortexa9-linux-gnueabihf-gcc -S test.c -emain -fomit-frame-pointer -O0
test.s
.arch armv7-a
.eabi_attribute 27, 3
.eabi_attribute 28, 1
.fpu vfpv3
.eabi_attribute 20, 1
.eabi_attribute 21, 1
.eabi_attribute 23, 3
.eabi_attribute 24, 1
.eabi_attribute 25, 1
.eabi_attribute 26, 2
.eabi_attribute 30, 6
.eabi_attribute 34, 1
.eabi_attribute 18, 4
.file "test.c"
.text
.align 2
.global main
.type main, %function
main:
@ args = 0, pretend = 0, frame = 24
@ frame_needed = 0, uses_anonymous_args = 0
@ link register save eliminated.
sub sp, sp, #24
str r0, [sp, #4]
str r1, [sp]
mov r3, #5
str r3, [sp, #16]
add r3, sp, #16
str r3, [sp, #12]
add r3, sp, #12
str r3, [sp, #20]
mov r3, #0
mov r0, r3
add sp, sp, #24
@ sp needed
bx lr
.size main, .-main
.ident "GCC: (ctng-1.21.0-229g-FA) 4.9.3"
.section .note.GNU-stack,"",%progbits
————————————————
版权声明:本文为CSDN博主「杨幂的咪」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/Hsu_smile/article/details/85050629