Question: You are to design, write, assemble, and simulate an assembly language program which will generate Fibonacci sequence numbers. Giving is a table NARR of byte-long

You are to design, write, assemble, and simulate an assembly language program which will generate Fibonacci sequence numbers. Giving is a table NARR of byte-long numbers (with a $00 sentinel). Each element in the table corresponds to the sequence number of a Fibonacci number to be generated. The actual calculation of the corresponding 4-byte Fibonacci numbers has to be implemented in a subroutine. The 4-byte Fibonacci numbers have to be passed back to the main program, which stores them in the RESARR array.

This is what I have so far, I just need it to be implemented into a subroutine.

This is a Motorola 68HC11 microcontroller

* Program description:

*

* This program will calculate the Nth element of the Fibonnaci sequence

* as a 4-byte number

*

* Pseudocode:

*

*

* unsigned int N=40

* unsigned int RESULT (4-byte variable)

* unsigned int PREV (4-byte variable)

* unsigned int NEXT (4-byte variable)

* unsigned int COUNT (1-byte variable)

*

*

* RESULT=1;

* PREV=1;

* COUNT = N;

* while(N>2){

* NEXT(lower two bytes) = RESULT (lower two bytes)+ PREV (lower two

bytes);

* NEXT(upper two bytes) = RESULT (upper two bytes);

* if( C-flag ==1) NEXT(upper two bytes) ++;

* NEXT(upper two bytes) += PREV (upper two bytes);

*

* (the above implements a 4-byte addition using two 2-byte

additions)

*

* PREV(upper two bytes) = RESULT (upper two bytes);

* PREV(lower two bytes) = RESULT (lower two bytes);

*

* RESULT(upper two bytes) = NEXT (upper two bytes);

* RESULT(lower two bytes) = NEXT (lower two bytes);

*

* N--;

* }

* }

*

* all variables reside in memory

*

**************************************

* start of data section

ORG $B000

N FCB 40

ORG $B010

RESULT RMB 4

* define any other variables that you might need here

PREV RMB 4

NEXT RMB 4

COUNT RMB 1

* start of your program

ORG $C000

LDD #0 clear upper two bytes of RESULT

STD RESULT

STD PREV clear upper two bytes of PREV

LDD #1

STD RESULT+2 RESULT = 1

STD PREV+2 PREV = 1

LDAA N

STAA COUNT

WHILE LDAA COUNT COUNT = N

CMPA #2 while(COUNT>2){

BLS ENDWHILE

LDD RESULT+2

ADDD PREV+2 NEXT(lower two bytes) = RESULT (lower two

bytes)

STD NEXT+2 + PREV (lower two

bytes);

LDD RESULT NEXT(upper two bytes) = RESULT (upper two

bytes);

IF BCC ENDIF IF_C-Flag ==1)

THEN ADDD #1 NEXT(upper two bytes) = ++;

ENDIF ADDD PREV

STD NEXT NEXT(upper two bytes) += PREV (upper two

bytes);

LDD RESULT

STD PREV PREV(upper two bytes) = RESULT (upper two

bytes);

LDD RESULT+2

STD PREV+2 PREV(lower two bytes) = RESULT (lower two

bytes);

LDD NEXT

STD RESULT RESULT(upper two bytes) = NEXT (upper two

bytes);

LDD NEXT+2

STD RESULT+2 RESULT(upper two bytes) = NEXT (upper two bytes);

DEC COUNT COUNT--;

BRA WHILE }

ENDWHILE

DONE BRA DONE

END

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!