0% found this document useful (0 votes)
20 views3 pages

Assign 13

Uploaded by

Ayush Howale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views3 pages

Assign 13

Uploaded by

Ayush Howale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

;NAME:AYUSH ARVIND HOWALE

;ROLL NO.:218
;SUB: MICROPROCESSOR

section .data
nummsg db "***Program to find Factorial of a number*** ",10
db "Enter the number : ",
nummsg_len equ $-nummsg

resmsg db "Factorial is : "


resmsg_len equ $-resmsg

thankmsg db 10,"Thank you ",10


thankmsg_len equ $-thankmsg

zerofact db " 00000001 "


zerofactlen equ $-zerofact

section .bss

dispbuff resb 16
result resb 4
num resb 1
num1 resb 1
numascii resb 3

%macro display 2
mov rax,01
mov rdi,01
mov rsi,%1
mov rdx,%2
syscall
%endmacro

%macro accept 2
mov rax,0
mov rdi,0
mov rsi,%1
mov rdx,%2
syscall
%endmacro

section .text

global _start

_start:

display nummsg,nummsg_len
accept numascii,3
call packnum8_proc
mov [num],bl

display resmsg,resmsg_len
mov al,[num]
cmp al,01h
jbe endfact

mov bl,[num]
call proc_fact
mov rbx,rax
call disp64_proc
jmp exit

endfact:
display zerofact,zerofactlen

exit:
display thankmsg,thankmsg_len

mov rax,60
mov rdi,0
syscall
ret

disp64_proc:

mov rdi,dispbuff
mov rcx,16

dispup1:
rol rbx,4
mov dl,bl
and dl,0fh
add dl,30h
cmp dl,39h
jbe dispskip1
add dl,07h
dispskip1:
mov [rdi],dl
inc rdi
loop dispup1

display dispbuff,16
ret
packnum8_proc:

mov bx,0
mov ecx,02
mov esi,numascii
up1:
rol bl,04
mov al,[esi]
cmp al,39h
jbe skip1
sub al,07h
skip1:
sub al,30h
add bl,al
inc esi
loop up1
ret

proc_fact:
cmp bl, 1
jne do_calculation
mov ax, 1
ret
do_calculation:
push rbx
dec bl
call proc_fact
pop rbx
mul bl
ret

You might also like