这学期有一门《微机原理》课,这是其中一个作业,怕自己丢失,就放博客上吧
datas segment
msg1 db 'the factor of n is: n! = $'
msg2 db 'press any key to continue...$'
n dw ?
datas ends
stacks segment
buffer dw 20 dup(0);此处输入堆栈段代码
stacks ends
codes segment
assume cs:codes,ds:datas,ss:stacks
start:
mov ax,datas
mov ds,ax
next1:
mov dx,offset msg
mov ah,9 ;输出input a number n=
int 21h
mov ah,1 ;输入n
int 21h
sub al,30h
cmp al,8 ;判断n是否大于8
ja next1
cmp al,0 ;判断n是否为0
je next2
; mov ah,0
mov cl,al
mov dx,offset msg1 ;输出the factor of n is: n! =
mov ah,9
int 21h
mov ax,1
let:
mul cx ;计算n!
loop let
;1 mov cx,0
mov bx,10
output1: ;计算十进制n!的位数存入cx中
mov dx,0
inc cx
idiv bx ;商存入ax,余数存入dx
push dx ;保存余数
cmp ax,0
jnz output1
output2:
pop dx ;取出余数,放入ax
add dx,0030h
;mov dl,al ;输出结果
mov ah,2
int 21h
loop output2
jmp over
next2:
mov dx,offset msg1
mov ah,9
int 21h
mov ax,1
mov dl,31h ;输出成绩
mov ah,2
int 21h
;jmp over
over:
;mov dl, 0dh ;输出回车符0dh
; mov ah, 02
; int 21h
; mov dl, 0ah ;输出回车符0dh
; mov ah, 02
;int 21h
mov dx,offset msg2 ;输出press any key to continue...
mov ah,9
int 21h
mov ah,1 ;等待输入
int 21h
mov ah,4ch
int 21h
codes ends
end start