September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
11
Task/Factorial/X86-Assembly/factorial-1.x86
Normal file
11
Task/Factorial/X86-Assembly/factorial-1.x86
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
global factorial
|
||||
section .text
|
||||
|
||||
; Input in ECX register (greater than 0!)
|
||||
; Output in EAX register
|
||||
factorial:
|
||||
mov eax, 1
|
||||
.factor:
|
||||
mul ecx
|
||||
loop .factor
|
||||
ret
|
||||
20
Task/Factorial/X86-Assembly/factorial-2.x86
Normal file
20
Task/Factorial/X86-Assembly/factorial-2.x86
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
global fact
|
||||
section .text
|
||||
|
||||
; Input and output in EAX register
|
||||
fact:
|
||||
cmp eax, 1
|
||||
je .done ; if eax == 1 goto done
|
||||
|
||||
; inductive case
|
||||
push eax ; save n (ie. what EAX is)
|
||||
dec eax ; n - 1
|
||||
call fact ; fact(n - 1)
|
||||
pop ebx ; fetch old n
|
||||
mul ebx ; multiplies EAX with EBX, ie. n * fac(n - 1)
|
||||
ret
|
||||
|
||||
.done:
|
||||
; base case: return 1
|
||||
mov eax, 1
|
||||
ret
|
||||
17
Task/Factorial/X86-Assembly/factorial-3.x86
Normal file
17
Task/Factorial/X86-Assembly/factorial-3.x86
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
global factorial
|
||||
section .text
|
||||
|
||||
; Input in ECX register
|
||||
; Output in EAX register
|
||||
factorial:
|
||||
mov eax, 1 ; default argument, store 1 in accumulator
|
||||
|
||||
.base_case:
|
||||
test ecx, ecx
|
||||
jnz .inductive_case ; return accumulator if n == 0
|
||||
ret
|
||||
|
||||
.inductive_case:
|
||||
mul ecx ; accumulator *= n
|
||||
dec ecx ; n -= 1
|
||||
jmp .base_case ; tail call
|
||||
Loading…
Add table
Add a link
Reference in a new issue