asked 165k views
5 votes
Assembler

Write a procedure that produces N values in the Fibonacci number series and stores them in an array of quadword. Input parameters should be a pointer to an array of quadword, a counter of the number of values to generator.
(1) Write a test program that calls your procedure, passing N = 52. the first value in the array will be 1, and the last value will be 32,951,280,099.
(2) Create a new sequence that starts with 1 and 5 instead of 0 and 1.
The Fibonacci sequence will be: 1,1,2,3,5,8...and up until 32,951,280,099
The modified Fibonacci sequence will be: 1,5,6,11,17,28...and so on.
(3) Create an output listing file and upload it with your *asm showing both Fibonacci sequences.

1 Answer

4 votes

Final answer:

Here is a procedure in assembler that generates N values in the Fibonacci number series and stores them in an array of quadwords.

Step-by-step explanation:

Here is a procedure in assembler that generates N values in the Fibonacci number series and stores them in an array of quadwords:

.data
array DWORD 0:52 DUP (?)
.code
fibonacci PROC
push ebp
mov ebp, esp
push ecx
push eax
push ebx
push esi
mov esi, 0
mov edx, [ebp+8]
mov ecx, [ebp+12]
L1: mov eax, esi
cmp eax, 1
ja L2
mov ebx, 1
jmp L3
L2: mov eax, [ebp+ebp+ebx*4-12]
mov eax, [ebp+esi*4-8]
add eax, edx
mov ecx, [ebp+edx*4-8]
mov eax, ecx
mov [ebp+esi*4-8], eax
L3: inc esi
cmp esi, [ebp+edx*4-4]
jne L1
pop esi
pop ebx
pop eax
pop ecx
pop ebp
ret
fibonacci ENDP
start:
mov eax, OFFSET array
push eax
dec eax
push eax
call fibonacci
answered
User Pascual
by
8.3k points