17-03-2014, 11:59 AM
Implementing Functions in an Assembly Program
Implementing Functions.pdf (Size: 226.8 KB / Downloads: 74)
Description of the Problem - Generating a Fibonacci Series
Write a program to generate the first ten elements of a Fibonacci series. In this series, the first
and second elements are zero and one, respectively. Each element that follows is obtained by
adding the previous two elements. Use a subroutine to generate the next element from the
previous two elements. Store the elements of the series starting at address FIBSER.
Writing the Program
Our plan for the solution of this problem is shown in figure L4.2(a). This flowchart shows the
use of a subroutine to generate an element of the series, store it in memory, and prepare for
generation of the next element.
The first step in the solution is initialization. It involves setting up a data segment,
generating the first two numbers of the series, and storing them at memory locations with
offset addresses FIBSER and FIBSER + 1. Then a pointer must be established to address the
locations for other terms of the series. This address will be held in the DI register. Finally, a
counter with initial value equal to 8 can be set up in ex to keep track of how many numbers
remain to be generated.