Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Hey emu8086, thanks

Thanks for the help. I was even able to understand how to lighten the program up. Check some of this out, you'll see what I mean:

.model small
.stack 100h
.data
Prompt db 10, 13, 'Enter a number 1-8: $'
msg2 db 10, 10, 13, 'Factorial is: $'
msg db 10, 10, 13, 'That is a zero fool. Try again. Enter a number 1-8: $'
msg3 db 10, 10, 13, 'Typing a nine will just get you a dirty messge.',10, 13, 'Try again,this time, try to remember what numbers are between 1-8: $'

.code
fact proc
mov ax, @data
mov ds,ax

mov dx,offset prompt
mov ah,9h
int 21h

mov ah, 01h; get character input
int 21h

mov ah, 0
sub ax, 30h; make it a number from ASCII char
push ax

comp:
cmp al, 1
jb do_over; jump if below 1
cmp al, 8
jg do_over2; jump if greater than 8
jmp cont

do_over2:
mov ax, 0
mov dx, offset msg3
mov ah,9h
int 21h
jmp Get_input

do_over:
mov ax, 0
mov dx, offset msg
mov ah,9h
int 21h

Get_input:
mov ah, 01h
int 21h
mov ah,0
sub ax, 30h
push ax
jmp comp

cont:
mov ah, 9h
mov dx, offset msg2
int 21h

call facto; factorial proc

call div10; proc to create the base 10

mov ah,4ch;send return to dos code
int 21h

fact endp

facto proc
pop bx; pop from stack
pop ax; pop from stack
push bx; push back onto stack

cmp ax,1; compare ax to 1
je lonley

push ax; onto stack
dec ax; simply decrease ax by 1
push ax; onto stack, decreased by 1
call facto; back to top of proc
pop bx; from stack
mul bx; multiply

lonley:
ret; to main next proc div10
Facto endp

div10 proc
mov cx,0

divi10:

mov dx, 0
mov bx, 10
div bx
push dx
add cx, 1
cmp ax, 0
jg divi10

disp10:

pop dx
add dl, 30h
mov ah, 02h
int 21h
loop disp10

ret; return after the call

div10 endp
end fact

Comments

Sign In or Register to comment.