Hey emu8086, thanks - Programmers Heaven

Howdy, Stranger!

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


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
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: $'

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

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

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

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

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

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

ret; to main next proc div10
Facto endp

div10 proc
mov cx,0


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


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

ret; return after the call

div10 endp
end fact


Sign In or Register to comment.