Python assembly language Problem 6: The Fibonacci sequence in assembly 15 points
ID: 3734188 • Letter: P
Question
Python assembly language
Problem 6: The Fibonacci sequence in assembly 15 points; individual-only Begin by downloading the following file: ps6pr6.txt Move it into your ps5partII folder from Problem Set 5, and open the file in a text editor. Your task is to write a Hmmm assembly-language version of the Python program that you wrote in Problem 5. Your program should begin by reading an integer n from the user. It should then call a separate function to generate and print the first n Fibonacci numbers while also computing their sum. After the function returns, the program should print the sum and halt. In other words, the start of your assembly-language program should be comparable to the main function that you wrote for Problem 5, and it should call a separate function that has the same functionality as the fib function that you wrote for Problem 5. Important: For full credit, your assembly-language program must employ a single separate function to generate and print the Fibonacci numbers, and to compute and return their sum Use call and jumpr instructions as we did in lecture. Here is a sample run of the program, in which we assume that the user enters 7: Enter a number: 7 1 1 13 Note that the first 7 values printed (the numbers 1 through 13) are the first 7 Fibonacci numbers, and the final value (the 33) is the sum of those 7 numbers.Explanation / Answer
CODE
ORG 100H
MOV AL,1
MOV AH,1
MOV CX,7 //calculating upto seventh number in fibonacci series
;
MOV DL,0
MOV SI,0 // SI is used as index
MOV SRS[SI],AL // putting first and second value in array
INC SI
MOV SRS[SI],AH
INC SI //increment to point first calculated value store point
FIB: //starting the fibonacci number calculating loop
PUSH AX
ADD AH,AL // S=F1+F2 next number in series
MOV DL,AH //saving the calculated number
MOV SRS[SI],DL //copying to the array
INC SI //pointing the next position in the array
POP AX //restoring the second number
MOV AL,AH //F1=F2
MOV AH,DL //F2=S
LOOP FIB //loop until all number is calculated
MOV CX,7H
MOV SI,0 // pointing to first index in the array
ADD: // summation loop
ADD BL,SRS[SI] // SRS is array for number stored
INC SI
LOOP ADD
SRS DB 12 DUP(0)
END
Output:
Enter a Number : 7
1 1 2 3 5 8 13 33
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.