mirror of
https://github.com/janishutz/eth-summaries.git
synced 2026-01-13 21:08:28 +00:00
[SPCA] Improve Stack section
This commit is contained in:
12
semester3/spca/code-examples/01_asm/06_factorial.s
Normal file
12
semester3/spca/code-examples/01_asm/06_factorial.s
Normal file
@@ -0,0 +1,12 @@
|
||||
factorial:
|
||||
pushq %rbx # Preserve frame pointer
|
||||
movl %edi, %ebx
|
||||
movl $1, %eax
|
||||
cmpl $1, %edi
|
||||
jle .QUIT # Base case reached: quit
|
||||
leal -1(%rdi), %edi # Prepare args for next function call
|
||||
call factorial
|
||||
imull %ebx, %eax # Use result of function call
|
||||
.QUIT:
|
||||
popq %rbx # Restore frame pointer
|
||||
ret
|
||||
Reference in New Issue
Block a user