Sparc Assembly

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 having a hard time with this assignement i cant get the pfib value to print out the fib sequence.

Program received signal SIGSEGV, Segmentation fault.
0x0001083c in start ()
0x0001083c <start+80>: ld [ %fp + %o0 ], %o1

 
program compiles when written in C
#include <stdio.h>
int main(void)
{
 
/*Initialize user input*/
int userinput;
int fib3; 
char choice;
 
/*First do loop*/
do
{
 
/*Fib1 and fib2; every time the user enters yes, 
these values are intialized to 1. so I have initialised inside the do, while loop.
*/
int fib1 = 1, fib2 = 1;
/*Prompt user for input*/
printf("\nThis program prints the Fibonacci sequence");
printf("\nEnter a limit on the largest number to be displayed: ");
scanf("%d", &userinput); /*Store user input*/
printf("\n%d ", fib1); /*Print fib sequence*/
 
/*Calulates fib sequence*/
do
{
printf("%d ", fib2);
fib3 = fib1 + fib2;
fib1 = fib2;
fib2 = fib3;
} while(fib3 <= userinput);
int j;
int max = 0;
int temp = fib1;
int final = 2;
 
/*Finds the greatest power of 2*/
for(j = 1; temp % j == 0 && j <= temp; j *= 2)
{
max = j;
}
printf("\nThe last number %d is disvisible by %d.\n", temp, max);
/*Prompts user to contine or stop loop*/
printf("\nDo you want to print a different sequence (y/n):");
scanf(" %c",&choice);
}
while(choice != 'n');
system("pause");
return 0;
}
  1. Relevant commands, code, scripts, algorithms:
prompt1:
.asciz "\nThis program prints the Fibonacci sequence"
.align 8
prompt2:
.asciz "\nEnter a limit on the largest number to be displayed: "
.align 8
number:
.asciz "%d"
.align 8
pfib1:
.asciz "\n%d "
.align 8
outfib:
.asciz "%d "
.align 8
uoutp:
.asciz "\nThe last number %d is disvisible by %d.\n"
.align 8
conte:
.asciz "\nDo you want to print a different sequence (y/n):"
.align 8
anser:
.asciz " %c"
.align 8
off:
.asciz "pause"
 
 
define(fib1, l0) ![%fp + %fib1]
define(fib2, l1) ![%fp + %fib2]
define(fib3, l2) ![%fp + %fib3]
define(j_r, l3) ![%fp + %j_r]
define(temp_r, l4) ![%fp + %temp_r]
define(userinput_r, l5) ![%fp + %userinput_r]
define(final_r, l6) ![%fp + %final_r]
define(max_r, l7) ![%fp + %max_r]
define(choice_r, l7) ![%fp + %choice_r]
 
.section ".text"
.align 4
.global main
.type main, #function
.proc 04
main:
save %sp, -152, %sp
 
start:
mov 1, %g1
st %g1, [%fp + %fib1]
mov 1, %g1
st %g1, [%fp + %fib2]
sethi %hi(prompt1), %g1
or %g1, %lo(prompt1), %o0
call printf, 0
nop
sethi %hi(prompt2), %g1
or %g1, %lo(prompt2), %o0
call printf, 0
nop
add %fp, -20, %o5
sethi %hi(number), %g1
or %g1, %lo(number), %o0
mov %o5, %o1
call scanf, 0
nop
sethi %hi(pfib1), %g1
or %g1, %lo(pfib1), %o0
ld [%fp + %fib1], %o1
call printf, 0
nop
while:
sethi %hi(outfib), %g1
or %g1, %lo(outfib), %o0
ld [%fp + %fib2], %o1
call printf, 0
nop
ld [%fp + %fib1], %o5
ld [%fp + %fib2], %g1
add %o5, %g1, %g1
st %g1, [%fp + %fib3]
ld [%fp + %fib2], %g1
st %g1, [%fp + %fib1]
ld [%fp + %fib3], %g1
st %g1, [%fp + %fib2]
ld [%fp + %fib3], %o5
ld [%fp-20], %g1
cmp %o5, %g1
bg swap
nop
b while
nop
swap:
st %g0, [%fp + %j_r]
ld [%fp + %fib1], %g1
st %g1, [%fp + %temp_r]
mov 2, %g1
st %g1, [%fp + %final_r]
mov 1, %g1
st %g1, [%fp + %max_r]
forloop:
ld [%fp + %temp_r], %g1
mov %g1, %o0
ld [%fp + %max_r], %o1
call .rem, 0
nop
mov %o0, %g1
cmp %g1, 0
bne printlast
nop
ld [%fp + %max_r], %o5
ld [%fp + %temp_r], %g1
cmp %o5, %g1
bg printlast
nop
ld [%fp + %max_r], %g1
st %g1, [%fp + %j_r]
ld [%fp + %max_r], %g1
add %g1, %g1, %g1
st %g1, [%fp + %max_r]
b forloop
nop
printlast:
sethi %hi(uoutp), %g1
or %g1, %lo(uoutp), %o0
ld [%fp + %temp_r], %o1
ld [%fp + %j_r], %o2
call printf, 0
nop
sethi %hi(conte), %g1
or %g1, %lo(conte), %o0
call printf, 0
nop
add %fp, -25, %o5
sethi %hi(anser), %g1
or %g1, %lo(anser), %o0
mov %o5, %o1
call scanf, 0
nop
ldub [%fp + %choice_r], %g1
sll %g1, 24, %g1
sra %g1, 24, %g1
cmp %g1, 110
be end
nop
b start
nop
end:
sethi %hi(off), %g1
or %g1, %lo(off), %o0
call system, 0
nop
mov 0, %g1
mov %g1, %i0
ret
restore
.size main, .-main
 
  1. The attempts at a solution (include all code and scripts):
    When running through debug -gdb I find where the problem occurs
    each time i write this program i get hung in the same spot.

Program received signal SIGSEGV, Segmentation fault.
0x0001083c in start ()
0x0001083c <start+80>: ld [ %fp + %o0 ], %o1

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

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

Well, segv is often failure to have null terminators where you expect them. Of course, using an address storage before you set it is pretty popular, too. Can you decipher which ld that is? Add some progress printouts.