用汇编求n!

这学期有一门《微机原理》课,这是其中一个作业,怕自己丢失,就放博客上吧

datas segment

msg db 'input a number n= $'
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
  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值