John Delmark Aguilar
Would you like to react to this message? Create an account in a few clicks or log in to continue.
John Delmark Aguilar

Personal Forum
 
HomeSearchLatest imagesRegisterLog in

 

 Factorial Assembly Language Code

Go down 
AuthorMessage
dElmARk
Admin
Admin
dElmARk


Posts : 92
Join date : 09/04/2012

Factorial Assembly Language Code Empty
PostSubject: Factorial Assembly Language Code   Factorial Assembly Language Code Icon_minitimeMon Dec 10, 2012 10:36 am

Code:

geti macro
 local exit,get
 xor bx,bx
 mov dx,bx
 mov cx,00ah
get:
 push bx
 ;Read character
 mov ah,01h
 int 21h
 xor ah,ah
 pop bx
 ;If enter stop
 cmp al,0dh
 jz exit
 sub al,30h
 ;Multply By 10
 push ax
 mov ax,bx
 mul cx
 mov bx,ax
 pop ax
 ;add
 add bx,ax
 ;redo
 jmp get
exit:
 mov ax,bx
endm

puti macro buffer
 local exit,put
 mov bx,0ah
 lea si,buffer
 add si,06h
 mov BYTE PTR [si],'$'
put:
 xor dx,dx
 dec si
 div bx
 add dl,30h
 mov [si],dl
 cmp ax,0h
 jnz put
 
 mov dx,si
 mov ah,09h
 int 21h
 
endm

puts macro msg
 push ax
 push dx
 mov dx,offset msg
 mov ah,09h
 int 21h
 pop dx
 pop ax
endm

data segment
 msg1 db 0dh,0ah,"Enter Number : $"
 msg2 db 0dh,0ah,"Factorial : $"
 buff db 20 dup(?)
data ends

assume cs:code,ds:data
code segment
start:
 mov ax,data
 mov ds,ax
 puts msg1
 geti
 push ax
 puts msg2
 pop ax
 mov cx,ax
 dec cx
 jz over
 xor dx,dx
 re:mul cx
 loop re
over:
 puti buff
 mov ah,4ch
 int 21h
code ends
end start
Back to top Go down
https://delmark.forumtl.com
 
Factorial Assembly Language Code
Back to top 
Page 1 of 1
 Similar topics
-
» Fibonacci Assembly Language Code
» Language Basics

Permissions in this forum:You cannot reply to topics in this forum
John Delmark Aguilar :: dElmARk Productions :: Assembly Language-
Jump to: