x86 Assembly

Moderators: None (Apply to moderate this forum)
Number of threads: 4563
Number of posts: 16029

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Hey emu8086, thanks Posted by stevem222 on 30 Sept 2002 at 6:34 AM
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

Report
Re: Hey emu8086, thanks Posted by Josh Code on 2 Oct 2002 at 12:56 PM
This message was edited by Josh Code at 2002-10-4 16:10:36





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.