Sponsored Content
Homework and Emergencies Homework & Coursework Questions program to find and print a Fibonacci sequence of numbers. --Errors Post 302715351 by kenjiro310 on Sunday 14th of October 2012 04:20:08 PM
Old 10-14-2012
Update compiles with errors

Code:
.section ".data"
/*Variables data section*/
intro: .asciz "\nThis program prints the Fibonacci sequence."     !Program purpose statemt
userp: .asciz "\nEnter a limit on the largest number to be displayed: "    !Prompt user to enter a number
number: .asciz "%d"     !number to be entered
formtp: .word 0 !where the user input number will be read in
pfib1: .asciz "\n%d "
outfib: .asciz "%d "
uoutp: .asciz  "\nThe last number %d is disvisible by %d.\n" !Power of 2
conte: .asciz "\nDo you want to print a different sequence (y/n):"      !Continue or stop statement
anser: .asciz "%c"
formta: .byte 0 !where the user input number will be read in
off:   .asciz "pause"

define(fib1, i4) !%fib1
define(fib2, i3) !%fib2
define(fib3, l0) !%fib3
define(j_r, l1)  !%j_r
define(temp_r, l2) !%temp_r
define(%uinput_r, l3) !%uinput_r
define(final_r, l4) !%final_r
define(max_r, l5) !%max_r

.align 4
.global main
.section ".text"

main: save %sp, -152, %sp

start:
                !Post program statement to the user
                mov        1, %fib1
                mov        1, %fib2
                set    intro, %o0
                call   printf
                nop

                !Prompts for userinput
                !Enter a limit on the largest number to be displayed
                set     userp, %o0
        call    printf
        nop

                set             number, %o0  !sets the type of data to be entered: integer
        set     formtp, %o1  !location where input will be stored
                call    scanf            !gets the input into the variable userinput
        nop

                !Store fib sequence
        set     pfib1, %o0   !sets the type of data to be entered: integer
        mov     %fib1, %o1
                call    printf        !print fibonacci sequence
        nop

while:          !Do loop that calculates the fib sequence and prints it
                set             outfib, %o0
                mov             %fib2, %o1   !printsf("%d ", fib2)
                call    printf
                nop
                mov             %fib1, %o2
                mov             %fib2, %o3
                add     %o2, %o3, %o5
                mov      %o5, %fib3   !fib3 = fib1 + fib2
                mov      %fib2, %o2
                mov      %o2, %fib1   !fib1 = fib2
                mov             %fib3, %o2
                mov             %o2, %fib2      !fib2 = fib3
                mov      %fib3, %o2
                mov             formtp, %o3
                cmp             %o2, %o3        !while(fib3 <= userinput)
                bg              swap
                nop
                b       while

swap:
                mov             %g0, %j_r         !int j
                mov             %fib1, %o0
                mov             %o0, %temp_r   !int temp = fib1
                mov             2, %o1
                mov             %o1, %final_r  !int final = 2
                mov             1, %o1
                mov             %o1, %max_r   !int max = 1

forloop:
                mov             %temp_r, %o1
                mov             %o1, %o0
                mov             %max_r, %o2
                call    start
                nop

                mov             %o0, %o1
                cmp             %o1, 0
                bne             printlast
                nop

                mov             %max_r, %o0
                mov             %temp_r, %o1
                cmp             %o0, %o1
                bg              printlast
                nop

                mov             %max_r, %o0
                mov             %o0, %j_r
                mov             %max_r, %o0
                add             %o0, %o0, %o0
                mov             %o0, %max_r
                b               forloop
                nop

printlast:
        set     uoutp, %o0      !The last number %d is disvisible by %d.\n"
                mov      %temp_r, %o1
                mov             %j_r, %o2
                call    printf
                nop

        set             conte, %o0   !Continue or stop statement
        call    printf
        nop

        add     %fp, -25, %o5  !User response to stop or continue
        set     anser, %o3
        mov     %o5, %o1
        call    scanf
        nop
        ldub    [formta], %o3
        sll     %o3, 24, %o3
        sra     %o3, 24, %o3
        cmp     %o3, 110
        be      done
        nop
        b       start
        nop

        done:                                                   !LL3
                set   off, %o0
        call    system, 0
        nop
        mov     0, %o0
        mov     %o0, %i0
        ret
        restore

Code:
ld: fatal: relocation error: R_SPARC_13: file /var/tmp//ccflMkZH.o: symbol <unknown>: value 0x20ac7 does not fit
ld: fatal: relocation error: R_SPARC_13: file /var/tmp//ccflMkZH.o: symbol <unknown>: value 0x20b33 does not fit
collect2: ld returned 1 exit status

Any idea how i can resolve this

Moderator's Comments:
Mod Comment edit by bakunin: you have already beeen asked to use CODE-tags when posting code - please do so!

Last edited by bakunin; 10-15-2012 at 04:21 AM..
 

10 More Discussions You Might Find Interesting

1. Post Here to Contact Site Administrators and Moderators

program to find the uncommon numbers between two files.

Hi, I need to extract the uncommon numbers from file1 and file2 For Example: File1 1 2 3 4 5 File2 1 2 3 4 5 6 (2 Replies)
Discussion started by: salaathi
2 Replies

2. Shell Programming and Scripting

Unix help to find blank lines in a file and print numbers on that line

Hi, I would like to know how to solve one of my problems using expert unix commands. I have a file with occasional blank lines; for example; dertu frthu fghtu frtty frtgy frgtui frgtu ghrye frhutp frjuf I need to edit the file so that the file looks like this; (10 Replies)
Discussion started by: Lucky Ali
10 Replies

3. Shell Programming and Scripting

Shell script to find the sum of first n Fibonacci numbers

pls give me the solution for this i need it for my exam pls pls pls Shell script to find the sum of first n Fibonacci numbers (1 Reply)
Discussion started by: Kshitija
1 Replies

4. Homework & Coursework Questions

Help with shell script to find sum of first n numbers of Fibonacci series

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Shell script to find sum of first n numbers of Fibonacci series 2. Relevant commands, code, scripts,... (0 Replies)
Discussion started by: Kshitija
0 Replies

5. UNIX for Dummies Questions & Answers

Why does fibonacci sequence script stop making sense at 92nd iteration?

So, Just for practice, I wrote a simple fibonacci sequence script in bash. (03:08:02\$ cat fib #!/usr/bin/bash ret () { echo -ne "\n" sleep .5 } a=1 b=2 echo -n $a #1 A ret echo -n $b #2 B ret (8 Replies)
Discussion started by: DeCoTwc
8 Replies

6. Shell Programming and Scripting

Need to find the gap in the sequence of numbers

Hi Guys, I have a file with numbers in sequence. The sequence have been broken somewhere.. I need to find out at which number the sequence has been broken... For an example, consider this sequence, it needs to give me output as 4 (as 5 is missing) and 6(as 7 is missing) Thanks for... (3 Replies)
Discussion started by: mac4rfree
3 Replies

7. Shell Programming and Scripting

How to find the matched numbers between 2 text file using perl program??

hi dudes, I nee you kind assistance, I have to find the matched numbers from 2 text files and output of matched numbers should be in another text file.. I do have text files like this , for example File 1 787 665*5-p 5454 545-p 445-p 5454*-p File 2 5455 787 445-p 4356 2445 144 ... (3 Replies)
Discussion started by: sureshraj
3 Replies

8. Shell Programming and Scripting

find common entries and match the number with long sequence and cut that sequence in output

Hi all, I have a file like this ID 3BP5L_HUMAN Reviewed; 393 AA. AC Q7L8J4; Q96FI5; Q9BQH8; Q9C0E3; DT 05-FEB-2008, integrated into UniProtKB/Swiss-Prot. DT 05-JUL-2004, sequence version 1. DT 05-SEP-2012, entry version 71. FT COILED 59 140 ... (1 Reply)
Discussion started by: manigrover
1 Replies

9. Shell Programming and Scripting

Find common numbers and print yes or no

Hi I have 2 files with following data First file, sp|Q676U5|A16L1_HUMAN, Autophagy-related protein 16-1 OS=Homo sapiens GN=ATG16L1 PE=1 SV=2, Maximum coiled-coil residue probability: 0.657 in position 163. Maximum dimeric residue probability: 0.288 in position 163. ... (1 Reply)
Discussion started by: manigrover
1 Replies

10. Programming

Program wont print prime numbers

The problem I'm having is that when you put in the two numbers the answer is just prime.... nothing. I cannot figure this out ive been working on this forever, can someone please god just tell me how to fix this without encrypted "hints". #include <iostream> #include <cmath> using... (3 Replies)
Discussion started by: c++newb
3 Replies
All times are GMT -4. The time now is 11:16 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy