program to find and print a Fibonacci sequence of numbers. --Errors

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:
    I am trying to convert a C language program over to Sparc Assembley and I am getting Undefined first referenced
    symbol in file
i3 /var/tmp//ccg4vymi.o
i4 /var/tmp//ccg4vymi.o
l0 /var/tmp//ccg4vymi.o
l1 /var/tmp//ccg4vymi.o
l2 /var/tmp//ccg4vymi.o
l3 /var/tmp//ccg4vymi.o
l4 /var/tmp//ccg4vymi.o
l5 /var/tmp//ccg4vymi.o
uinput_r /var/tmp//ccg4vymi.o
outfib /var/tmp//ccg4vymi.o
ld: fatal: Symbol referencing errors. No output written to k9
collect2: ld returned 1 exit status

I think it has something to do with how i am trying to Define my variables

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

.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 "
oufib: .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: .word 0 !where the user input number will be read in
stopgo: .word 0 !where the user input number will be read in
off: .asciz "pause"

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

main: save %sp, -152, %sp

start:
!Post program statement to the user
mov 1, %o0
st %o0, [%fp + fib1]
mov 1, %o1
st %o1, [%fp + 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
ld [%fp + fib1], %o1
call printf !print fibonacci sequence
nop

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

swap:
st %g0, [%fp + j_r] !int j
ld [%fp + fib1], %o0
st %o0, [%fp + temp_r] !int temp = fib1
mov 2, %o1
st %o1, [%fp + final_r] !int final = 2
mov 1, %o1
st %o1, [%fp + max_r] !int max = 1

forloop:
ld [%fp + temp_r], %o1
mov %o1, %o0
ld [%fp + max_r], %o2
call start
nop

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

ld [%fp + max_r], %o0
ld [%fp + temp_r], %o1
cmp %o0, %o1
bg printlast
nop

ld [%fp + max_r], %o0
st %o0, [%fp + j_r]
ld [%fp + max_r], %o0
add %o0, %o0, %o0
st %o0, [%fp + max_r]
b forloop
nop

printlast:
set uoutp, %o0 !The last number %d is disvisible by %d.\n"
ld [%fp + temp_r], %o1
ld [%fp + 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 [%fp + uinput_r], %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 
  1. Relevant commands, code, scripts, algorithms:
 $ m4 k9.m > k9.s
$ gcc k9.s -o k9
  1. The attempts at a solution (include all code and scripts):
    maybe i should define my varibles like so
define(fib1, i4) 
define(fib2, i3) 
define(fib3, l0) 
define(j_r, l1) 
define(temp_r, l2) 
define(userinput_r, l3) 
define(final_r, l4) 
define(max_r, l5) 

and not in a frame pointer.

  1. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
    Georgia State University Atlanta Ga course name CSC 3210 instructor name Chimua Umoja

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

Take your old C code (it compiles with no errors right?) we'll call it old.c

gcc -S old.c

A new file old.s which is assembler (for the system you run the gcc command on) will be created. If you run the command on sparc you get sparc assembler.

.file   "fu1.c"
        .global .rem
        .section        ".rodata"
        .align 8
.LLC0:
        .asciz  "\nThis program prints the Fibonacci sequence"
        .align 8
.LLC1:
        .asciz  "\nEnter a limit on the largest number to be displayed: "
        .align 8
.LLC2:
        .asciz  "%d"
        .align 8
.LLC3:
        .asciz  "\n%d "
        .align 8
.LLC4:
        .asciz  "%d "
        .align 8
.LLC5:
        .asciz  "\nThe last number %d is disvisible by %d.\n"
        .align 8
.LLC6:
        .asciz  "\nDo you want to print a different sequence (y/n):"
        .align 8
.LLC7:
        .asciz  " %c"
        .align 8
.LLC8:
        .asciz  "pause"
        .section        ".text"
        .align 4
        .global main
        .type   main, #function
        .proc   04
main:
        !#PROLOGUE# 0
        save    %sp, -152, %sp
        !#PROLOGUE# 1
.LL2:
        mov     1, %g1
        st      %g1, [%fp-32]
        mov     1, %g1
        st      %g1, [%fp-36]
        sethi   %hi(.LLC0), %g1
        or      %g1, %lo(.LLC0), %o0
        call    printf, 0
         nop
        sethi   %hi(.LLC1), %g1
        or      %g1, %lo(.LLC1), %o0
        call    printf, 0
         nop
        add     %fp, -20, %o5
        sethi   %hi(.LLC2), %g1
        or      %g1, %lo(.LLC2), %o0
        mov     %o5, %o1
        call    scanf, 0
         nop
        sethi   %hi(.LLC3), %g1
        or      %g1, %lo(.LLC3), %o0
        ld      [%fp-32], %o1
        call    printf, 0
         nop
.LL5:
        sethi   %hi(.LLC4), %g1
        or      %g1, %lo(.LLC4), %o0
        ld      [%fp-36], %o1
        call    printf, 0
         nop
        ld      [%fp-32], %o5
        ld      [%fp-36], %g1
        add     %o5, %g1, %g1
        st      %g1, [%fp-24]
        ld      [%fp-36], %g1
        st      %g1, [%fp-32]
        ld      [%fp-24], %g1
        st      %g1, [%fp-36]
        ld      [%fp-24], %o5
        ld      [%fp-20], %g1
        cmp     %o5, %g1
        bg      .LL6
        nop
        b       .LL5
         nop
.LL6:
        st      %g0, [%fp-44]
        ld      [%fp-32], %g1
        st      %g1, [%fp-48]
        mov     2, %g1
        st      %g1, [%fp-52]
        mov     1, %g1
        st      %g1, [%fp-40]
.LL8:
        ld      [%fp-48], %g1
        mov     %g1, %o0
        ld      [%fp-40], %o1
        call    .rem, 0
         nop
        mov     %o0, %g1
        cmp     %g1, 0
        bne     .LL9
        nop
        ld      [%fp-40], %o5
        ld      [%fp-48], %g1
        cmp     %o5, %g1
        bg      .LL9
        nop
        ld      [%fp-40], %g1
        st      %g1, [%fp-44]
        ld      [%fp-40], %g1
        add     %g1, %g1, %g1
        st      %g1, [%fp-40]
        b       .LL8
         nop
.LL9:
        sethi   %hi(.LLC5), %g1
        or      %g1, %lo(.LLC5), %o0
        ld      [%fp-48], %o1
        ld      [%fp-44], %o2
        call    printf, 0
         nop
        sethi   %hi(.LLC6), %g1
        or      %g1, %lo(.LLC6), %o0
        call    printf, 0
         nop
        add     %fp, -25, %o5
        sethi   %hi(.LLC7), %g1
        or      %g1, %lo(.LLC7), %o0
        mov     %o5, %o1
        call    scanf, 0
         nop
        ldub    [%fp-25], %g1
        sll     %g1, 24, %g1
        sra     %g1, 24, %g1
        cmp     %g1, 110
        be      .LL3
        nop
        b       .LL2
         nop
.LL3:
        sethi   %hi(.LLC8), %g1
        or      %g1, %lo(.LLC8), %o0
        call    system, 0
         nop
        mov     0, %g1
        mov     %g1, %i0
        ret
        restore
        .size   main, .-main

Thanks for the heads up. I am now trying to declare my variables in the assembly file so i wont need the *.c file and clues as to how i would do that. I tried using frame pointers to my own variables with no luck

I think you missed one point. gcc -S is going to generate REALLY good assembler, with some optimizations. You should use that as template.

Since you seem to want to rewrite the code read here about optimizations and how to control them. Maybe that is your assignment. In that case:

Optimize Options - Using the GNU Compiler Collection (GCC)

.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
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