Skip to content

Instantly share code, notes, and snippets.

@officialcjunior
Last active December 9, 2019 11:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save officialcjunior/3ccd73d4a1dc12086043b08d2ba0324c to your computer and use it in GitHub Desktop.
Save officialcjunior/3ccd73d4a1dc12086043b08d2ba0324c to your computer and use it in GitHub Desktop.
Program to find the factorial of a number, written in assembly language
BITS 32
extern printf
extern scanf
section .rodata
fmt: db "%d", 0
output: db "factorial is %d",10,0
section .text
global main
main:
push ebp
mov ebp, esp
sub esp, 0x10
lea eax, [ebp-0x4] #entering the value
push eax
push fmt
call scanf
mov ecx, 1
mov ebx, 0
mov edx, dword [ebp-0x4] ; moving the entered value to edx for comparison
L1:
add ebx, 1
imul ecx, ebx ; the quotient is stored in ecx
cmp ebx, edx ; to make sure that we multiply till ebx reaches the value entered.
jl L1
push ecx
push output
call printf
leave
ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment