473,406 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Write a program to find and print a Fibonacci sequence of numbers in assembly

1
Question Details:

Write a program to find and print a Fibonacci sequence of numbers. The Fibonacci sequence is defined as follow:

Fn = Fn-2 + Fn-1, n >= 0

F0 = 0, F1 = 1, F2 = 1

Your program should prompt the user to enter a limit and indicate whether the last number in the sequence printed is either even or odd.

Here is what the user will see when the program is executed:

This program prints the Fibonacci sequence

Enter a limit on the largest number to be displayed: 50

1 1 2 3 5 8 13 21 34

The last number in this sequence is an even number.

Do you want to print a different sequence (Y/N): n



the code is giving me segmentation fault core dumped and i can not test for the even and add #




.section ".data"
/*Variables*/
prompt: .asciz "\nThis program prints the Fibonacci sequence"
prompt2: .asciz "\nEnter a limit on the largest number to be displayed:"
prompt5: .asciz "\nDo you want to print a different sequence (Y/N):"

input: .word 0
yesNo: .byte 0
nl: .asciz "\n"
format1: .asciz "%d%c"
format2: .asciz "%c%c"

!CODE!

.align 8
.global main
.section ".text"

define(f_1, l0)
define(f_2, l1)
define(count, l2)

main:
save %sp, -96, %sp
repeat:
!!!!Welcome and initial prompt!!!
set prompt, %o0 !set welcome message
call printf !print it
nop

set prompt2, %o0 !ask fo a number
call printf
nop

set format1, %o0 !input needs to be an interger
set input, %o1 !address where input is stored
set nl, %o2 !dump
call scanf
nop


ld [%o1], %o0
mov %o0, %count
mov 1, %f_1
mov 1, %f_2
mov 1, %o0
call printf
nop
mov 1, %o0
call printf
nop
loop:
add %f_1, %f_2, %o0
call printf
mov %f_1, %f_2
mov %o0, %f_1
cmp %f_1, %count
ble loop



!!!Continue?!!!
set prompt5, %o0
call printf
nop

set format2, %o0 !getting a character and a newline
set yesNo, %o1
set nl, %o2
call scanf
nop

set yesNo, %l0
ldub [%l0], %o0 !get the ys/no from memory
cmp %o0, 'y'
be repeat
nop !yes then try again


ret !get out
restore
Oct 19 '09 #1
1 8812
donbock
2,426 Expert 2GB
Each processor has its own assembly language. Nobody can help you unless you identify the processor you're using. It might also be helpful to know who the assembler vendor is.

By the way, this is the C/C++ forum.
Oct 19 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

33
by: Nick Evans | last post by:
Hello there, I have been on and off learning to code (with python being the second language I have worked on after a bit of BASIC). What I really want to know is, if you are going to actually...
28
by: dleecurt | last post by:
Hello, I have a small problem, I am trying to write a program that will calculate the Fibonacci number series, and I have the code complete with one problem. I used a long in to store the numbers,...
5
by: Niks | last post by:
Can anybody explain me what is a "Fibonacci search"? even an URL will do. Thanks for reading.
14
by: felixnielsen | last post by:
Im actually kinda embarassed to ask this question... @code start #include <iostream> int main() { unsigned long long a = 1; unsigned long long b = 1; for (int i = 0; i < 45; i++) { a += b;...
5
by: Protoman | last post by:
Here's a program I wrote that calcs the fibonacci numbers and writes them to a file, from 1-50. It prints to the screen just fine, but it only prints the last number, Fib(50) to the file. Code:...
8
by: andrew.smith.cpp | last post by:
Hello how Can i get this kind of output? 1,2,3,5,8,13,21 i try it with loop but could print it. Thanks
1
by: astrogirl77 | last post by:
I'm new to C++ and am hoping to find help with coding a simple C program, am wanting to obtain code and functioning exe's. I code in an old version of Visual Basic 4.0, I have a simple app that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.