Created
December 6, 2016 21:37
-
-
Save yeputons/954a97ecf40f54861ae41cccee82e298 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.data | |
.text | |
.globl main | |
# ===== MAIN BODY ===== | |
# S_LABEL ("main") | |
main: | |
# S_FUN_BEGIN ({args=[], locals=["a"; "b"; "x"], max_stack=2}) | |
pushl %ebp | |
movl %esp, %ebp | |
pushl %ebx | |
pushl %esi | |
pushl %edi | |
subl $12, %esp | |
# var a -> -16(%ebp) | |
# var b -> -20(%ebp) | |
# var x -> -24(%ebp) | |
# ===== x := 2 ===== | |
# S_PUSH (2) | |
movl $2, %ebx | |
# S_ST ("x") | |
movl %ebx, -24(%ebp) | |
# S_LD ("x") | |
movl -24(%ebp), %ebx | |
# S_CALL ("fun_b", 1) | |
pushl %ecx | |
pushl %ebx | |
call fun_b | |
addl $4, %esp | |
popl %ecx | |
movl %eax, %ebx | |
# S_CALL ("write", 1) | |
pushl %ecx | |
pushl %ebx | |
call write | |
addl $4, %esp | |
popl %ecx | |
movl %eax, %ebx | |
# S_DROP () | |
# ===== a := 1 ===== | |
# S_PUSH (1) | |
movl $1, %ebx | |
# S_ST ("a") | |
movl %ebx, -16(%ebp) | |
# ===== b := 2 ===== | |
# S_PUSH (2) | |
movl $2, %ebx | |
# S_ST ("b") | |
movl %ebx, -20(%ebp) | |
# S_LD ("b") | |
movl -20(%ebp), %ebx | |
# S_LD ("a") | |
movl -16(%ebp), %ecx | |
# S_CALL ("fun_a", 2) | |
pushl %ecx | |
pushl %ebx | |
pushl %ecx | |
call fun_a | |
addl $8, %esp | |
popl %ecx | |
movl %eax, %ebx | |
# S_CALL ("write", 1) | |
pushl %ecx | |
pushl %ebx | |
call write | |
addl $4, %esp | |
popl %ecx | |
movl %eax, %ebx | |
# S_DROP () | |
# ===== FUN_END ===== | |
# S_PUSH (0) | |
movl $0, %ebx | |
# S_RET ("lbl_1") | |
movl %ebx, %eax | |
jmp lbl_1 | |
# S_LABEL ("lbl_1") | |
lbl_1: | |
# S_FUN_END () | |
movl %ebp, %esp | |
subl $12, %esp | |
popl %edi | |
popl %esi | |
popl %ebx | |
popl %ebp | |
ret | |
# ===== FUN a ===== | |
# S_LABEL ("fun_a") | |
fun_a: | |
# S_FUN_BEGIN ({args=["x"; "y"], locals=[], max_stack=2}) | |
pushl %ebp | |
movl %esp, %ebp | |
pushl %ebx | |
pushl %esi | |
pushl %edi | |
subl $0, %esp | |
# var x -> 8(%ebp) | |
# var y -> 12(%ebp) | |
# ===== return (x + y) ===== | |
# S_LD ("x") | |
movl 8(%ebp), %ebx | |
# S_LD ("y") | |
movl 12(%ebp), %ecx | |
# S_BINOP ("+") | |
addl %ecx, %ebx | |
# S_RET ("lbl_2") | |
movl %ebx, %eax | |
jmp lbl_2 | |
# ===== FUN_END ===== | |
# S_PUSH (0) | |
movl $0, %ebx | |
# S_RET ("lbl_2") | |
movl %ebx, %eax | |
jmp lbl_2 | |
# S_LABEL ("lbl_2") | |
lbl_2: | |
# S_FUN_END () | |
movl %ebp, %esp | |
subl $12, %esp | |
popl %edi | |
popl %esi | |
popl %ebx | |
popl %ebp | |
ret | |
# ===== FUN b ===== | |
# S_LABEL ("fun_b") | |
fun_b: | |
# S_FUN_BEGIN ({args=["y"], locals=[], max_stack=1}) | |
pushl %ebp | |
movl %esp, %ebp | |
pushl %ebx | |
pushl %esi | |
pushl %edi | |
subl $0, %esp | |
# var y -> 8(%ebp) | |
# ===== y := 5 ===== | |
# S_PUSH (5) | |
movl $5, %ebx | |
# S_ST ("y") | |
movl %ebx, 8(%ebp) | |
# S_LD ("y") | |
movl 8(%ebp), %ebx | |
# S_CALL ("write", 1) | |
pushl %ecx | |
pushl %ebx | |
call write | |
addl $4, %esp | |
popl %ecx | |
movl %eax, %ebx | |
# S_DROP () | |
# ===== return y ===== | |
# S_LD ("y") | |
movl 8(%ebp), %ebx | |
# S_RET ("lbl_3") | |
movl %ebx, %eax | |
jmp lbl_3 | |
# ===== FUN_END ===== | |
# S_PUSH (0) | |
movl $0, %ebx | |
# S_RET ("lbl_3") | |
movl %ebx, %eax | |
jmp lbl_3 | |
# S_LABEL ("lbl_3") | |
lbl_3: | |
# S_FUN_END () | |
movl %ebp, %esp | |
subl $12, %esp | |
popl %edi | |
popl %esi | |
popl %ebx | |
popl %ebp | |
ret |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MAIN BODY | |
S_LABEL ("main") | |
S_FUN_BEGIN ({args=[], locals=["a"; "b"; "x"], max_stack=2}) | |
// x := 2 | |
S_PUSH (2) | |
S_ST ("x") | |
S_LD ("x") | |
S_CALL ("fun_b", 1) | |
S_CALL ("write", 1) | |
S_DROP () | |
// a := 1 | |
S_PUSH (1) | |
S_ST ("a") | |
// b := 2 | |
S_PUSH (2) | |
S_ST ("b") | |
S_LD ("b") | |
S_LD ("a") | |
S_CALL ("fun_a", 2) | |
S_CALL ("write", 1) | |
S_DROP () | |
// FUN_END | |
S_PUSH (0) | |
S_RET ("lbl_1") | |
S_LABEL ("lbl_1") | |
S_FUN_END () | |
// FUN a | |
S_LABEL ("fun_a") | |
S_FUN_BEGIN ({args=["x"; "y"], locals=[], max_stack=2}) | |
// return (x + y) | |
S_LD ("x") | |
S_LD ("y") | |
S_BINOP ("+") | |
S_RET ("lbl_2") | |
// FUN_END | |
S_PUSH (0) | |
S_RET ("lbl_2") | |
S_LABEL ("lbl_2") | |
S_FUN_END () | |
// FUN b | |
S_LABEL ("fun_b") | |
S_FUN_BEGIN ({args=["y"], locals=[], max_stack=1}) | |
// y := 5 | |
S_PUSH (5) | |
S_ST ("y") | |
S_LD ("y") | |
S_CALL ("write", 1) | |
S_DROP () | |
// return y | |
S_LD ("y") | |
S_RET ("lbl_3") | |
// FUN_END | |
S_PUSH (0) | |
S_RET ("lbl_3") | |
S_LABEL ("lbl_3") | |
S_FUN_END () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment