微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决递归阶乘如何显示大于 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 举报,一经查实,本站将立刻删除。