Sparc Assembly

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Sparc Assembly
# 1  
Old 10-20-2012
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

Code:
 
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;
}

2. Relevant commands, code, scripts, algorithms:
Code:
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

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


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

Last edited by kenjiro310; 10-20-2012 at 01:33 PM..
# 2  
Old 10-23-2012
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Understanding Assembly Code

As the title suggests, I want to better understand the following assembly code: section .text global main ; must be declared for linker (gcc) main: ; tell linker entry point mov edx, len ; message length mov ecx, msg ; message to write... (2 Replies)
Discussion started by: Azrael
2 Replies

2. What is on Your Mind?

Can assembly language be dispensed with ?

Hi. I learned C in high school and am proficient in it:D. At the college while learning microcontrollers there was a short course on assembly language which I skipped:p but had no trouble as most of the application programming had to be done in C. Should I go back n learn assembly language as I... (9 Replies)
Discussion started by: priyadarshianu
9 Replies

3. Programming

Assembly 8085

Hi eneryone, Im trying to learn about assemply 8085 in order to make a project i have. First of all which emulator to use? I work in linux and I currently istalled GNUSim8085. Also, maybe somewhere I can find some simple examples? The project is about making an array saved in specific... (8 Replies)
Discussion started by: giampoul
8 Replies

4. Programming

Why Assembly Language?

Hi guys, Assembly language is a low level language designed in 1950's, both system and application programs were written in assembly at that time. There is no question of assembly being very effecient compared to the other high level languages. But it is very cumbersome to write programs in... (9 Replies)
Discussion started by: gabam
9 Replies

5. Programming

Fibonacci (assembly)

When i run this with gcc filename.s -o filename. It is giving fatal error: Unknown opcode at define registers. Anyhelp will be appreciated .section ".data" prompt: .asciz "\nThis program prints the Fibonacci sequence" prompt2: .asciz "\nEnter a limit on the largest number to be displayed:"... (2 Replies)
Discussion started by: Learnerabc
2 Replies

6. Programming

Help with assembly code

I want make simple assembly code for some thing like this a^6+6a^2+2a and range of a is between -3 to 3. I tried but it is not working properly. As this is my first assembly program that I am going to try, I want some help with it. I found this example online but i dont want this kind of... (2 Replies)
Discussion started by: Learnerabc
2 Replies

7. Programming

Assembly Language ( compile )

Can someone explain how to compile assembly language code. I made my first assembly language code, but don't know how to run it. I know i can debug with gdb, but is there any way to just compile it and get the answer like in C and java compilers. (3 Replies)
Discussion started by: Learnerabc
3 Replies

8. Programming

Need assembly code for C program

Dear Buddies, I need assembly code for a compiled c program in unix. Kindly help me.... Thanking you in advance. (1 Reply)
Discussion started by: karthik537
1 Replies

9. Shell Programming and Scripting

Unix assembly help

Hey guys, well I'm extremely knew to Unix so any help advice is very appreciated. What I am trying to do is assemble a source code (Programming from the Ground Up: Chapter 3: Your First Programs) The source code named "FINDING A MAXIMUM VALUE" is the code I am trying to link and run, but I... (1 Reply)
Discussion started by: ac09
1 Replies

10. UNIX for Dummies Questions & Answers

Assembly vs C programming

I am currently looking into an os on developed on an x86 platformwhich contains certain assembly code written in .s files(NASM- compatible ) instead of using C I was wondering why C could not be used to do low level stuff instead? Do anyone have any idea or could enligthen me?Appreciate any help... (0 Replies)
Discussion started by: duoshock
0 Replies
Login or Register to Ask a Question