string
This commit is contained in:
70
example/pseudo/t.s
Normal file
70
example/pseudo/t.s
Normal file
@@ -0,0 +1,70 @@
|
||||
.text
|
||||
zerop:
|
||||
pushq %rbp
|
||||
movq %rsp, %rbp
|
||||
cmpl $0, %edi
|
||||
jnz .Lbb2
|
||||
movl $1, %eax
|
||||
jmp .Lbb3
|
||||
.Lbb2:
|
||||
movl $0, %eax
|
||||
.Lbb3:
|
||||
leave
|
||||
ret
|
||||
.type zerop, @function
|
||||
.size zerop, .-zerop
|
||||
/* end function zerop */
|
||||
|
||||
.text
|
||||
factorial:
|
||||
pushq %rbp
|
||||
movq %rsp, %rbp
|
||||
subq $8, %rsp
|
||||
pushq %rbx
|
||||
movq %rdi, %rbx
|
||||
callq zerop
|
||||
movq %rbx, %rdi
|
||||
cmpl $0, %eax
|
||||
jnz .Lbb6
|
||||
movq %rdi, %rbx
|
||||
subq $1, %rdi
|
||||
callq factorial
|
||||
movq %rbx, %rdi
|
||||
imulq %rdi, %rax
|
||||
jmp .Lbb7
|
||||
.Lbb6:
|
||||
movl $1, %eax
|
||||
.Lbb7:
|
||||
popq %rbx
|
||||
leave
|
||||
ret
|
||||
.type factorial, @function
|
||||
.size factorial, .-factorial
|
||||
/* end function factorial */
|
||||
|
||||
.data
|
||||
.balign 8
|
||||
fstr:
|
||||
.ascii "fac 3 = %d\n"
|
||||
.byte 0
|
||||
/* end data */
|
||||
|
||||
.text
|
||||
.globl main
|
||||
main:
|
||||
pushq %rbp
|
||||
movq %rsp, %rbp
|
||||
movl $3, %edi
|
||||
callq factorial
|
||||
movq %rax, %rsi
|
||||
leaq fstr(%rip), %rdi
|
||||
movl $0, %eax
|
||||
callq printf
|
||||
movl $0, %eax
|
||||
leave
|
||||
ret
|
||||
.type main, @function
|
||||
.size main, .-main
|
||||
/* end function main */
|
||||
|
||||
.section .note.GNU-stack,"",@progbits
|
||||
Reference in New Issue
Block a user