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 a Motorola 68HC11 microcontroller.
This is what I have so far,
* 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
and
* start of data section
ORG $B000
NARR FCB 1, 2, 5, 10, 20, 128, 254, 255, $00
SENTIN EQU $00
ORG $B010
RESARR RMB 32
* define any variables that your MAIN program might need here
* REMEMBER: Your subroutine must not access any of the main
* program variables including NARR and RESARR.
ORG $C000
LDS #$01FF initialize stack pointer
* start of your main program
* define any variables that your SUBROUTINE might need here
ORG $D000
* start of your subroutine
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started