You are to design, write, assemble, and simulate an assembly language program which will generate
the Nth number in the Fibonacci sequence.
What is the Fibonacci Sequence?
You start with initializing the first two numbers of the sequence to 1 (F1 = F2 = 1). The rule to generate
the next number is to add the previous two numbers: FN = FN-1 + FN-2.
This results in the following sequence: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 …
Given to you is N as a 1-byte unsigned integer variable with 1 ≤ N ≤ 255. Your program has to
calculate the Nth number in the Fibonacci sequence as a 2-byte number to be stored in RESULT in
BIG-ENDIAN format. For example, if N=10, your answer should be $0037 (the two-byte hex
equivalent of 55); if N=24, your answer should be $B520 (the two-byte hex equivalent of 46368).
While for N > 24 the corresponding Fibonacci number is larger than 65535 (the largest number than
can be represented with the 2-bytet RESULT variable), the program will still be able to correctly
calculate the lower 2-bytes of the Fibonacci number.
1. Your program should work for any N value, not just the one given.
2. Your program is NOT allowed to change the number stored in N.
3. You have to use the program skeleton provided for Lab2. Do not change the data section or you
will lose points! This means: do not change the ‘ORG $B000’ and ‘ORG $B010’ statements or
‘N FCB’ or ‘RESULT RMB 2’. You are allowed to change the value assigned to N to simulate
different numbers. If you need to define additional variables, please add them after the ‘RESULT
RMB 2’ statement.
4. You must terminate your program correctly using the STOP instruction as shown in class.
5. The program must only have one exit point (i.e., only one STOP instruction at the end of the
program is allowed).
6. You do not have to optimize your algorithm or your assembly program for speed.
7. You have to provide a pseudo-code solution. In your pseudo code, do NOT use a for loop, but
either a while or a do-until structure to implement a loop. Also, do NOT use any “goto”, “break”,
“exit”, or “return” statements in your pseudocode.
8. The structure of your assembly program should match the structure of your pseudo code 1-to-1
(e.g., if the pseudo code shows a while structure, your assembly program should also have a while
9. Make sure that you implement any if-then, if-then-else, while, or do-until structures the way you
learned it in class. Incorrectly implemented structures will result in points lost.
10. Any assembler or simulator error/warning messages appearing when assembling/simulating your
submitted program will result in up to 50 points lost.
You should test your program with at least five different N values; for example:
A. N = 1 -> RESULT = $0001
B. N = 2 -> RESULT = $0001
C. N = 100 -> RESULT = $BFC3
D. N = 200 -> RESULT = $E395
E. N = 255 -> RESULT = $7EE2
PLEASE NOTE: Your program will be tested by us using random Ns. If your program does not
produce correct result for those random numbers, you will lose up to 25 points (see grading guidelines
Your program should include a header containing your name, student number, the date you wrote the
program, and the lab assignment number. Furthermore, the header should include the purpose of the
program and the pseudocode solution of the problem. At least 85% of the instructions should have
meaningful comments included – not just what the instruction does; e.g., don’t say “increment the
register A” which is obvious from the INCA instruction; say something like “increment the loop
counter” or whatever this incrementing does in your program. You can ONLY use branch labels
related to structured programming, i.e., labels like IF, IF1, THEN, ELSE, ENDIF, WHILE, ENDWHL,
DOUNTL, DONE, etc. DO NOT use labels like LOOP, JOE, etc. Remember: labels need to be
unique. So, for example, if you have two if-then structures, you should use the labels IF,THEN,
ENDIF for the first structure and IF1,THEN1, ENDIF1 for the second one.
YOU ARE TO DO YOUR OWN WORK IN WRITING THIS PROGRAM!!! While you can
discuss the problem in general terms with the instructor and fellow students, when you get to the
specifics of designing and writing the code, you are to do it yourself. Re-read the section on academic
dishonesty in the class syllabus. If there is any question, consult with the instructor.
Electronically submit your .ASM file on Canvas by 1:00pm on the due date. Late submissions or resubmissions (with a 10% grade penalty) are allowed for up to 24 hours (please see the policy on late
submission in the course syllabus).
Because of some inherent lack of reliability designed into computers, and Murphy’s law by which this
design feature manifests itself in the least convenient moment, you should start your work early.
Excuses of the form:
“my memory stick went bad,”
“I could not submit my program,”
“my computer froze up, and I lost all my work;”
should be directed to the memory stick manufacturer, Canvas system administrator, and your local
Microsoft/Apple vendor respectively.
Grade Requirements and Breakdown
The assignment is worth 100 points. The following deductions will be made (maximum deduction of
– submitted program not related to lab assignment: -100 points
– Pseudocode incomplete or missing: -50 points
– wrong algorithm implemented: -50 points
– for-loop used in pseudocode: -15 points
– “break/exit/return/goto” used in pseudo-code: -10 points
Program must produce correct results
– program does not produce correct result for certain N values: up to -25 points
Program must have good structure
– program does not assemble or is incomplete: -50 points
– assembler error/warning messages during assembly: -25 points
– simulator error/warning messages during simulation: -25 points
– assembler error/warning messages because of incorrect commenting: -10 points
– multiple STOP instructions used: -10 points
– program changes N variable: -5 points
– structure X incorrectly implemented: -5 points for each structure
– hardcoded addresses used in program: -5 points
Program must match pseudo code 1-to-1
– program structure does not match pseudo-code (program implements structure X, but different or no
structure shown in pseudo code; or vice versa): -5 points for each structure
– branch for signed numbers used but variables unsigned; or vice versa: -5 points for each branch
– conditional branch used does not match pseudo-code condition: -5 points
– no program comments at all: -20 points
– program not commented enough: -10 points
– program description missing: -5 points
– incomplete program header: -5 points
– incorrect branch labels used: -5 points
Note: This list is by no means comprehensive but only lists the most common deductions.