递归阶乘如何显示大于 6 的数字Assembly nasm

问题描述

我从一个在线网站学习了递归程序集。该程序只会使用阶乘数 1-3 运行,这意味着它只显示 1-6 个数字,对吗?那么如果我想输入大于 3 的数字,例如 10,该怎么办? 谢谢大家的回答

这是代码

section .text
   global _start         ;must be declared for using gcc
    
_start:                  ;tell linker entry point

   mov bx,3             ;for calculating factorial 3
   call  proc_fact
   add   ax,30h
   mov  [fact],ax
    
   mov    edx,len        ;message length
   mov    ecx,msg        ;message to write
   mov    ebx,1          ;file descriptor (stdout)
   mov    eax,4          ;system call number (sys_write)
   int    0x80           ;call kernel

   mov   edx,1            ;message length
   mov    ecx,fact       ;message to write
   mov    ebx,4          ;system call number (sys_write)
   int    0x80           ;call kernel
    
   mov    eax,1          ;system call number (sys_exit)
   int    0x80           ;call kernel
    
proc_fact:
   cmp   bl,1
   jg    do_calculation
   mov   ax,1
   ret
    
do_calculation:
   dec   bl
   call  proc_fact
   inc   bl
   mul   bl        ;ax = al * bl
   ret

section .data
msg db 'Factorial 3 is:',0xa    
len equ $ - msg         

section .bss
fact resb 1

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)