Last active
December 9, 2019 11:24
-
-
Save officialcjunior/3ccd73d4a1dc12086043b08d2ba0324c to your computer and use it in GitHub Desktop.
Program to find the factorial of a number, written in assembly language
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
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