ASSUME 神纯指 CS:CODE
START: MOV CX,6
MOV BX,5
CALL DIGUIMI
CALL DIGUIAX
MOV AH,4CH
INT 21H
================================
DIGUIMI PROC NEAR
cx为幂次,bx为底
ax 中返回 乘幂
CMP CX,0
JNE @DIGUIMI
MOV AX,1
RET
@DIGUIMI:
DEC CX
CALL DIGUIMI
MUL BX
RET
DIGUIMI ENDP
=================================
DIGUIAX PROC NEAR
递归显示 AX 中的无符号数(10进制)
PUSH BX
PUSH DX
MOV DX,0
MOV BX,10
DIV BX
游配 CMP AX,0
JE @DIGUIAX1
CALL DIGUIAX
@DIGUIAX1:
OR DX,30H
MOV AH,2
INT 21H
POP DX
裤好 POP BX
RET
DIGUIAX ENDP
=================================
CODE ENDS
END START
#include <stdio.h>int fac(int n){
if (n) return fac(n-1)*n
return 1
}void main()
{
printf("%d\n", fac(6)) // 数字随枣消液你改桥好,也可以通凳物过键盘输入。
}
可计算1-10000的阶改备乘野余DATAS SEGMENT
string db"Please input a number(0-10000):" ,0dh,0ah
wrongstring db" A number please! ",0ah,0dh,'$'
inputbuffer db6,?,6 dup(?)
c10 dw10 输入时进制转换的数
n dw? 要求阶乘的数
m dw? 步长
c dw? 进位颂歼滚
i dw?
outputbuffer dw30000 dup(?)
DATAS ENDS
*******************************************************************************
STACKS SEGMENT
此处输入堆栈段代码
STACKS ENDS
*******************************************************************************
CODES SEGMENT
ASSUMECS:CODES,DS:DATAS,SS:STACKS
START:
MOV AX,DATAS
MOV DS,AX
-------------------------------------------------------
main proc
call input
call fractor
mov cx,di
routput:循环输出
push cx
mov di,cx
call output
pop cx
dec cx
cmp cx,0
jge routput
displaylength:
mov dl,0dh
mov ah,2
int 21h
mov dl,0ah
mov ah,2
int 21h
jmp Start
exit:
mov ah,07h
int 21h
mov ax,4c00h
INT 21H
main endp
-------------------------------------------------------
--------------------------------------------------------
input proc near
lea bx,string
mov cx, 33
disstring:
mov dl,[bx]
mov ah,2
int 21h
inc bx
loop disstring
jmp inputinit
wronginput:
lea dx,wrongstring
mov ah,9
int 21h
inputinit:
lea dx,inputbuffer 装载输入缓冲区首地址
mov ah,0ah 输入功能代码
int 21h 从键盘输入一个数,以回车键结束
mov ax,0累加器清0
mov cl,inputbuffer+1循环次数
mov ch,0
lea bx,inputbuffer+2装载字符存放区首地址
inputone:
mul c10
mov dl,[bx]
cmp dl,'0'
jbwronginput
cmp dl,'9'
jawronginput
and dl,0fh
add al,dl
adc ah,0
inc bx
loop inputone
mov n,ax
mov dl,0dh
mov ah,2
int 21h
mov dl,0ah
mov ah,2
int 21h
ret
input endp
-----------------------------------------------------
fractor proc near
mov cx,n
mov i,1d
mov m,0d
push dx
mov di,0d
mov ax,di
mov bx,2d
mul bx
mov si,ax
pop dx
mov outputbuffer[si],1d
ctrli:
mov c,0
mov di,0d
ctrldi:
cmp di,m
jbe done
jmp cmpc
done:
push dx
mov ax,di
mov bx,2d
mul bx
mov si,ax
pop dx
mov ax,outputbuffer[si]
mov bx,i
mul bx
add ax,c
adc dx,0
mov bx,10000
div bx
mov c,ax
push dx
mov ax,di
mov bx,2d
mul bx
mov si,ax
pop dx
mov outputbuffer[si],dx
inc di
jmp ctrldi
cmpc:
cmp c,0
jathree1
jmp next
three1:
inc m
mov ax,c
mov outputbuffer[si+2],ax
next:
inc i
cmp cx,0
jng if0
loop ctrli
if0:
mov di,m
ret
fractor endp
-----------------------------------------------------
output proc near
C2:
push dx
mov ax,di
mov bx,2d
mul bx
mov si,ax
pop dx
mov bx,outputbuffer[si]
bid proc
mov cx,10000
mov ax,bx
mov dx,0
div cx
mov bx,dx
mov cx,1000
call ddiv
mov cx,100
call ddiv
mov cx,10
call ddiv
mov cx,1
call ddiv
ret
bid endp
---------------------------------
ddiv proc
mov ax,bx
mov dx,0
div cx
mov bx,dx
mov dl,al
add dl,30h
mov ah,02h
int 21h
ret
ddiv endp
ret
output endp
--------------------------------------------
CODES ENDS
END START
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)