Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Assembly 

Basic tutorial of Factorial in assembly M68000

I everyone, i post this simply code written by myself. It contains some comments.
I wish someone can appreciate it.
P.S. : sorry for my bad english 😭
 
Code
START:              
         main:             sub.l #8, a7        #we must reserve some space in the stack for the recursive call;we'll reserve 32 bit            
                           move.l num, d0      #we move the num from the memory to register d0
                           move.l #1, d2       #we copy 1 in d2
             
                           bra Fatt            #branch to the label Fatt

       Fatt_recursive:     sub.l  #4, a7       #reserving 32 bit in the stack(a7)
                           move.l d0, (a7)     #we move d0 in the stack zone pointed by register a7
                           sub.l  #1, d0       #we decrease d0
                           bsr fatt            #branch subroutine
                           
                           
                           move.l (a7)+,d1     #this two lines are the most important we move the content of the stack in position a7 (with post increase) and we
                           mulu d1, d2         #put it in d1 and we mul (unsigned) d1 and d2, the result at last we'll be written in d1 register
                           
                           rts


       Fatt:               cmp  #1, d0         #we compare d0 with 1 if d0 become 1 we'll start with the recursive call
                           bgt  Fatt_recursive #d0 is greater than 1 so we branch to the label fatt_recursive
                           
                           
                           rts



   SIMHALT             ; halt simulator

   num: dc.l 6
   ris: dc.l 0

   END    START        ; last line of source


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Assembly] by AroMar 9, 2021 04:29 AM 157 29,662 Mar 9, 2021 04:29 AM
Last Post: cghhhhasd
[Assembly] by timFeb 22, 2019 06:39 AM 2 416 Feb 22, 2019 06:39 AM
Last Post: PELock
[Delphi] by SymbioticAug 19, 2016 03:44 PM 34 2,857 Aug 19, 2016 03:44 PM
Last Post: Securifier