Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. [70 points] Write an assembly program to compute the nth number in the Fibona

ID: 3725020 • Letter: 1

Question

1. [70 points] Write an assembly program to compute the nth number in the Fibonacci series. The first and second Fibonacci numbers are 0 and 1, respectively. Every subsequent Fibonacci numbers are the sum of the previous two Fibonacci numbers. For example, the third Fibonacci number is 1 (i.e., 0 + 1), the fourth is 2 (i.e., 1+1), the fifth is 3 (i.e., 1+2), and so on. The program must use a loop to compute Fibonacci numbers and display their values on the screen. Display the first 10, 15 and 20 numbers as test cases. 2. [30 points] Extend your solution to Problem 1 so that instead of displaying the list in the increasing order, the program shows the Fibonacci numbers in reverse order. Particularly, after constructing the original list, initialize another list with the same size in which you build the contents of this list from the original one in the reverse order.

Explanation / Answer

1.

.DATA

resArr DB ?

.CODE

START:

LEA SI,RES

MOV [SI],00H ; load 0 at first position

INC SI

MOV [SI],01H ; load 1 at second position

INC SI

MOV CL,0AH ; Load counter to iterate over, because two elements 0 & 1 already loaded in the array

MOV AX,00H

MOV BX,01H

;Fibonacci series

L1:

BEZ CL, EXIT

ADD AX,BX

DAA   

MOV [SI],AX ; Move sum to current array location and then update AX & BX

MOV AX,BX

MOV BX,[SI]

INC SI ; increment array location

INC CL ; increment loop counter

LOOP L1

EXIT:

INT 3H ; Terminate the Program

END START

2.

.DATA

resArr DB ?

revArr DB ?

.CODE

START:

LEA SI,resArr

MOV [SI],00H ; load 0 at first position

INC SI

MOV [SI],01H ; load 1 at second position

INC SI

MOV CL,08H ; Load counter to iterate over, because two elements 0 & 1 already loaded in the array

MOV AX,00H

MOV BX,01H

;Fibonacci series

L1:

BEZ CL, REV

ADD AX,BX

DAA   

MOV [SI],AX ; Move sum to current array location and then update AX & BX

MOV AX,BX

MOV BX,[SI]

INC SI ; increment array location

INC CL ; increment loop counter

LOOP L1

REV:

MOV [DI], revArr

MOV CL,0AH ; reset counter

L2:

BEZ CL, EXIT

MOV [DI], [SI]

INC DI

DEC SI

INC CL

LOOP L2

EXIT:

INT 3H ; Terminate the Program

END START

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote