编译阶段翻译成平台汇编代码,是在预编译阶段上加码,将C/C++代码翻译成平台相关的汇编代码。
示例:
1)用户程序
/*@brief test demo-for-compile-to-asm? show you here@author wen`xuanpei@email 15873152445@163.com(query for any question here)
*/
#include <stdio.h>int main(int argc, char **argv){if(argc == 1){puts("hello world-0!\n");}else {--argc;switch(argc){default:break;case 1:/*dead-loop-1*/puts("hello world-1!\n");for(;;){;}break;case 2:/*dead-loop-2*/puts("hello world-2!\n");while(1){;}break;case 3:/*dead-loop-3*/puts("hello world-3!\n");do{;}while(1);break;case 4:/*dead-loop-4*/puts("hello world-4!\n");__dead_loop:{;}goto __dead_loop;break;}}return 0;
}2)编译
gcc test.c -S
g++ test.c -S3)翻译成平台相关的汇编代码
	.file	"test.c".section	.rodata
.LC0:.string	"hello world-0!\n"
.LC1:.string	"hello world-1!\n"
.LC2:.string	"hello world-2!\n"
.LC3:.string	"hello world-3!\n"
.LC4:.string	"hello world-4!\n".text.globl	main.type	main, @function
main:
.LFB0:.cfi_startprocpushq	%rbp.cfi_def_cfa_offset 16.cfi_offset 6, -16movq	%rsp, %rbp.cfi_def_cfa_register 6subq	$16, %rspmovl	%edi, -4(%rbp)movq	%rsi, -16(%rbp)cmpl	$1, -4(%rbp)jne	.L2movl	$.LC0, %edicall	putsjmp	.L3
.L2:subl	$1, -4(%rbp)movl	-4(%rbp), %eaxcmpl	$2, %eaxje	.L5cmpl	$2, %eaxjg	.L6cmpl	$1, %eaxje	.L7jmp	.L3
.L6:cmpl	$3, %eaxje	.L8cmpl	$4, %eaxje	.L9jmp	.L3
.L7:movl	$.LC1, %edicall	puts
.L10:jmp	.L10
.L5:movl	$.LC2, %edicall	puts
.L11:jmp	.L11
.L8:movl	$.LC3, %edicall	puts
.L12:jmp	.L12
.L9:movl	$.LC4, %edicall	puts
.L13:jmp	.L13
.L3:movl	$0, %eaxleave.cfi_def_cfa 7, 8ret.cfi_endproc
.LFE0:.size	main, .-main.ident	"GCC: (GNU) 4.8.5 20150623 (Red Hat 4.8.5-44)".section	.note.GNU-stack,"",@progbits
尾声:如果不知道预编译,可以参考下列文章
1)gcc/g++:预编译阶段宏定义-CSDN博客
2)gcc/g++:预编译阶段取消宏定义-CSDN博客
3)gcc/g++:预编译阶段查看模块生成目标的层级依赖-CSDN博客
4)gcc/g++:预编译阶段查看模块生成目标的直接依赖-CSDN博客
5)gcc/g++:预编译阶段查看层级依赖可用宏列表-CSDN博客
6)gcc/g++:预编译阶段嵌入头文件并完成替换-CSDN博客
7)gcc/g++:预编译阶段寻找头文件-CSDN博客