dElmARk Admin
Posts : 92 Join date : 09/04/2012
| Subject: Factorial Assembly Language Code Mon 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 | |
|