In high-level language, such as C language to write a factorial very easy, it is now familiar with the Linux use at/T assembly format to write a program to calculate the factorial bar
The first is to use the jump command to implement. The second is to use a function to implement
Convention: This program does not print the results on the standard output.
Need to use GDB debug to view
The wording of a
#as filename.s-o filename.o#ld filename.o-o filename # gdb filename.section. data.section. Text.globl _START_START:MOVL $%eax #result = 1movl $6,%ecx # n = 5cmpl $,%ecxjle. Loop_exit.start_loop:imull%ecx,%eaxsubl $ ,%ecxcmpl $, %ecxjge. START_LOOPMOVL%eax,%EBXMOVL $,%eaxint $0x80. LOOP_EXIT:MOVL $,%eaxint $0x80
--------------------function to be updated-------------------------two: function recursion
. section. data.section. text.globl _START_START:PUSHL $5call. Jcmovl%eax,%EBXMOVL,%eaxint $0x80. JC:PUSHL%ebpmovl%esp,%EBPPUSHL%ebxsubl $4,%ESPMOVL 8 (%EBP),%ebx #get n = 5;movl $,%eax
View Result: Echo $? Of course, using GDB to view it will be clearer.
using echo $? To view, it seems that n more than 6, the result is not correct, so the GDB insurance
------Computing the factorial of N in the assembly language of Linux