Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Program received signal SIGSEGV, Segmentation fault. 0x0001083c in start () 0x00

ID: 3652972 • Letter: P

Question

Program received signal SIGSEGV, Segmentation fault. 0x0001083c in start () 0x0001083c : ld [ %fp + %o0 ], %o1 prompt1: .asciz " This program prints the Fibonacci sequence" .align 8 prompt2: .asciz " Enter a limit on the largest number to be displayed: " .align 8 number: .asciz "%d" .align 8 pfib1: .asciz " %d " .align 8 outfib: .asciz "%d " .align 8 uoutp: .asciz " The last number %d is disvisible by %d. " .align 8 conte: .asciz " Do 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

Explanation / Answer

A segfault means your program is writing to memory that it shouldn't. Rather than "run", use "next" and "skip" to step through your program - then you'll find where the segfault is actually occurring. Also make sure you compile with -g so it puts debug info into the executable. Then your gdb session should look like this: gdb test b main r n n n n ... "b main" sets a break point at main(). "r" runs till that breakpoint. "n" steps to the next instruction. For much more really useful stuff, see the gdb docs. Good luck! http://ubuntuforums.org/showthread.php?t=531746 check this thread