Loops 如何在汇编语言中循环

Loops 如何在汇编语言中循环,loops,assembly,x86,masm,irvine32,Loops,Assembly,X86,Masm,Irvine32,如何计算斐波那契数列中的前12个值并将其放入EAX reg中。和显示调用转储文件?使用间接寻址,我知道我需要一个for循环,但我甚至不知道该怎么做。任何帮助或提示都将不胜感激 INCLUDE Irvine32.inc ; (insert symbol definitions here) .data ; (insert variables here) Fibonacci BYTE 1, 1, 10 DUP (?) .code main PROC ; (insert ex

如何计算斐波那契数列中的前12个值并将其放入EAX reg中。和显示调用转储文件?使用间接寻址,我知道我需要一个for循环,但我甚至不知道该怎么做。任何帮助或提示都将不胜感激

      INCLUDE Irvine32.inc

; (insert symbol definitions here)

.data

; (insert variables here)
   Fibonacci BYTE 1, 1, 10 DUP (?)

.code
main PROC

; (insert executable instructions here)


    ; (This below will show hexa contents of string.)
      mov   esi, OFFSET Fibonacci       ; offset the variables
      mov   ebx,1                   ; byte format
      mov   ecx, SIZEOF Fibonacci       ; counter
      call  dumpMem 


    exit        ; exit to operating system
main ENDP

; (insert additional procedures here)

END main

您可以这样做一个循环:

mov ecx,12
your_label:
; your code
loop your_label
mov ecx,12
your_label:
; your code
dec ecx
jnz your_label
循环指令递减
ecx
并跳到指定的标签,除非
ecx
等于零。您也可以这样构造相同的循环:

mov ecx,12
your_label:
; your code
loop your_label
mov ecx,12
your_label:
; your code
dec ecx
jnz your_label

您可以这样做一个循环:

mov ecx,12
your_label:
; your code
loop your_label
mov ecx,12
your_label:
; your code
dec ecx
jnz your_label
循环指令递减
ecx
并跳到指定的标签,除非
ecx
等于零。您也可以这样构造相同的循环:

mov ecx,12
your_label:
; your code
loop your_label
mov ecx,12
your_label:
; your code
dec ecx
jnz your_label

您确定需要一个for循环来实现您的目标,因此可能for循环在汇编中的C实现将帮助您:

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
循环的代码生成 对于(i=0;i<100;i++) { . . . } *数据寄存器D2用于实现i。 *将D2设置为零(i=0) CLR.L D2 L1 . . . *(i++)的增量i 附录1,D2 *检查for循环退出条件(i<100) CMPI.L#100,D2 *如果设置了小于标志,则分支到for循环的开头 BLT.S L1
来源:

您确定需要一个for循环来实现您的目标,因此可能for循环在汇编中的C实现将帮助您:

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
循环的代码生成 对于(i=0;i<100;i++) { . . . } *数据寄存器D2用于实现i。 *将D2设置为零(i=0) CLR.L D2 L1 . . . *(i++)的增量i 附录1,D2 *检查for循环退出条件(i<100) CMPI.L#100,D2 *如果设置了小于标志,则分支到for循环的开头 BLT.S L1
来源:

这看起来像是68k汇编程序,而OP中的代码(未标记为)是x86。这看起来像是68k汇编程序,而OP中的代码(未标记为)是x86。