我正在尝试将以下循环编写为汇编语言。该代码读取用户输入并输出斐波那契数。例如,如果用户输入10,则程序将显示斐波那契数列的前10个数字。如果可以,请帮助!
while (i <= n) {
if (i == n)
System.out.print(num1);
else
System.out.print(num1 + " + ");
int sum = num1 + num2;
num1 = num2;
num2 = sum;
i++;
环境
NOTE
示例
program Fibonacci;
#include("stdlib.hhf");
static
Loops: int32;
Number1: int32:= 0;
Number2: int32:= 1;
begin Fibonacci;
// Prompt user for input
stdout.put("Enter a number: ");
// Get user input
stdin.get(Loops);
// Loop for the requested amount
for (mov(0, ECX); ECX < Loops; inc(ECX)) do
// Print the Fn element
stdout.put(Number1, nl);
// Calculate the Fn+2 element
mov(Number1, EAX);
add(EAX, Number2);
// Store the Fn+1 element as the next Fn element
mov(Number2, Number1);
// Store the Fn+3 element as the Fn+2 element
mov(EAX, Number2);
endfor;
end Fibonacci;
无静态变量
program Fibonacci;
#include("stdlib.hhf");
begin Fibonacci;
xor(EBX, EBX);
mov(1, EDX);
stdout.put("Enter a number: ");
stdin.geti32();
for (mov(0, ECX); ECX < EAX; inc(ECX)) do
stdout.put((type int32 EBX), nl);
mov(EDX, EBP);
add(EBX, EDX);
mov(EBP, EBX);
endfor;
end Fibonacci;