How to loop in assembly language

后端 未结 3 941
遥遥无期
遥遥无期 2021-02-11 08:39

How would I calculate the first 12 values in the Fibonacci number sequence and be able to place it in EAX reg. and display calling DumpRegs? Using Indirect addressing I know I n

3条回答
  •  庸人自扰
    2021-02-11 09:14

    You determined that you need a for loop to achieve your goal, so maybe the C implementation of the for loop, in assembly, will help you:

    Code Generation for For Loop
    
    for (i=0; i < 100; i++)
    {
      . . .
    }
    
          * Data Register D2 is used to implement i.
          * Set D2 to zero (i=0)
          CLR.L D2
    
      L1  
          . . .
          * Increment i for (i++)
          ADDQ.L #1, D2
          * Check for the for loop exit condition ( i < 100)
          CMPI.L #100, D2
          * Branch to the beginning of for loop if less than flag is set
          BLT.S L1
    

    SOURCE: eventhelix.com

提交回复
热议问题