汇编

关于查看 c 的等价汇编源码。

编写 main.c 文件

#include<stdio.h>
int main(){
  printf("hello");
  return 0 ;
}

执行命令 gcc -S main.c 可以得到 main.s 这个便是汇编的文件,.s 为汇编源文件的后缀。其中文件内的注释为;

main.s 文件

	.section	__TEXT,__text,regular,pure_instructions
	.build_version macos, 11, 3	sdk_version 11, 3
	.globl	_main                           ; -- Begin function main
	.p2align	2
_main:                                  ; @main
	.cfi_startproc
; %bb.0:
	sub	sp, sp, #32                     ; =32
	stp	x29, x30, [sp, #16]             ; 16-byte Folded Spill
	add	x29, sp, #16                    ; =16
	.cfi_def_cfa w29, 16
	.cfi_offset w30, -8
	.cfi_offset w29, -16
	stur	wzr, [x29, #-4]
	adrp	x0, l_.str@PAGE
	add	x0, x0, l_.str@PAGEOFF
	bl	_printf
	mov	w8, #1
	mov	x0, x8
	ldp	x29, x30, [sp, #16]             ; 16-byte Folded Reload
	add	sp, sp, #32                     ; =32
	ret
	.cfi_endproc
                                        ; -- End function
	.section	__TEXT,__cstring,cstring_literals
l_.str:                                 ; @.str
	.asciz	"hello"

.subsections_via_symbols

因为用 m1 的本子转换得到的。用电脑自带的 /usr/bin/as。编译成功无法运行。可能平台相关。

评论列表