zoukankan      html  css  js  c++  java
  • 自制编译器 青木峰郎 笔记 Ch15 编译表达式和语句

    15.1 确认编译结果

    cbc --print-asm -fverbose-asm xx.cb可以看到汇编代码。gcc -S -o - xx.c也可以。

    root@cf43f429204e:/# cbc --print-asm -fverbose-asm if_test.cb 
    .file	"if_test.cb"
    	.section	.rodata
    .LC0:
    	.string	"OK"
    .LC1:
    	.string	"NO"
    .LC2:
    	.string	"ERR"
    	.text
    .globl main
    	.type	main,@function
    main:
    	# ---- Stack Frame Layout -----------
    	# (%ebp): return address
    	# 4(%ebp): saved %ebp
    	# 8(%ebp): argc
    	# 12(%ebp): argv
    	# -----------------------------------
    	pushl	%ebp
    	movl	%esp, %ebp
    	# line 4: if(1) if (2) { puts("OK"); }
    	# Int {
    	movl	$1, %eax
    	# }
    	testl	%eax, %eax
    	jnz	.L0
    	jmp	.L1
    .L0:
    	# line 4: if (2) { puts("OK"); }
    	# Int {
    	movl	$2, %eax
    	# }
    	testl	%eax, %eax
    	jnz	.L2
    	jmp	.L3
    .L2:
    	# line 4: puts("OK"); }
    	# Call {
    	  # Str {
    	movl	$.LC0, %eax
    	  # }
    	pushl	%eax
    	call	puts
    	addl	$4, %esp
    	# }
    	jmp	.L4
    .L3:
    	# line 5: if(3) {puts("NO");}
    	# Int {
    	movl	$3, %eax
    	# }
    	testl	%eax, %eax
    	jnz	.L5
    	jmp	.L6
    .L5:
    	# line 5: puts("NO");}
    	# Call {
    	  # Str {
    	movl	$.LC1, %eax
    	  # }
    	pushl	%eax
    	call	puts
    	addl	$4, %esp
    	# }
    	jmp	.L7
    .L6:
    	# line 6: puts("ERR");}
    	# Call {
    	  # Str {
    	movl	$.LC2, %eax
    	  # }
    	pushl	%eax
    	call	puts
    	addl	$4, %esp
    	# }
    .L7:
    .L4:
    .L1:
    	# line 7: return 0;}
    	# Int {
    	movl	$0, %eax
    	# }
    	jmp	.L8
    .L8:
    	movl	%ebp, %esp
    	popl	%ebp
    	ret
    	.size	main,.-main
    
    

    15.2 x86汇编的对象与DSL

  • 相关阅读:
    [HDU] 2084 数塔 入门dp
    一些实用的小技术,不定时更新^_^
    上传图片的综合验证
    一个典型web接口处理
    js控制背景音乐播放
    心开始平和起来
    冲突域广播域
    可怜的我的啊~~
    祈祷
    昨夜小楼又东风...
  • 原文地址:https://www.cnblogs.com/xuesu/p/14385848.html
Copyright © 2011-2022 走看看