main+0x58: nop
main+0x5c: add %fp, -0x1c, %o5
main+0x60: ld [%o5], %g1
main+0x64: ld [%g1], %o4
main+0x68: add %g1, 0x4, %g1
main+0x6c: st %g1, [%o5]
main+0x70: sethi %hi(0x10c00), %g1
main+0x74: or %g1, 0x118, %o0
main+0x78: ld [%fp - 0x18], %o1
main+0x7c: mov %o4, %o2
main+0x80: call +0x101dc
main+0x84: nop
main+0x88: ld [%fp - 0x18], %g1
main+0x8c: add %g1, 0x1, %g1
main+0x90: st %g1, [%fp - 0x18]
main+0x94: ba -0x4c
main+0x98: nop
main+0x9c: mov %g1, %i0
main+0xa0: ret
main+0xa4: restore
%g1 (r01) temporary value
> fibonacci::dis
fibonacci: save %sp, -0x80, %sp
[%fp + 0x44] = %i0 = n
fibonacci+4: st %i0, [%fp + 0x44]
[%fp - 0x14] = prev_number = 0
fibonacci+8: clr [%fp - 0x14]
[%fp - 0x18] = curr_number = 1
fibonacci+0xc: mov 0x1, %g1
fibonacci+0x10: st %g1, [%fp - 0x18]
if (n >= MAX_FIB_REPRESENTABLE) {
fibonacci+0x14: ld [%fp + 0x44], %g1
fibonacci+0x18: cmp %g1, 0x30
please note that: 0x30 = 48 = 49 - 1
or "cmp %g1, 0x31, bl +0x28"
branch on less or equal
fibonacci+0x1c: ble +0x28
fibonacci+0x20: nop
printf("Fibonacci(%d) cannot be represented in a 32 bit word\n", n)
{
fibonacci+0x24: sethi %hi(0x10c00), %g1
fibonacci+0x28: or %g1, 0xb8, %o0
[%fp + 0x44] = %g1 = n
fibonacci+0x2c: ld [%fp + 0x44], %o1
fibonacci+0x30: call +0x102f4
fibonacci+0x34: nop
}
exit(1)
fibonacci+0x38: mov 0x1, %o0
fibonacci+0x3c: call +0x102ac
fibonacci+0x40: nop
[%fp - 0x1c] = i = 2
fibonacci+0x44: mov 0x2, %g1
fibonacci+0x48: st %g1, [%fp - 0x1c]
The start of the for statement:
[%fp - 0x1c ] = %o5 = i
fibonacci+0x4c: ld [%fp - 0x1c], %o5
[%fp + 0x44 ] = %g1 = n
fibonacci+0x50: ld [%fp + 0x44], %g1
i < n
fibonacci+0x54: cmp %o5, %g1
branch on greater or equal
fibonacci+0x58: bge +0x5c
fibonacci+0x5c: nop
%o3 = fib_array;
fibonacci+0x60: sethi %hi(0x20c00), %g1
fibonacci+0x64: or %g1, 0x340, %o3
[%fp - 0x1c] = %g1 = i
fibonacci+0x68: ld [%fp - 0x1c], %g1
%o4 = %g1 * 2
shift left logic
fibonacci+0x6c: sll %g1, 0x2, %o4
[%fp - 0x14 ] = %o5 = prev_number
fibonacci+0x70: ld [%fp - 0x14], %o5
[%fp - 0x18] = %g1 = curr_number
fibonacci+0x74: ld [%fp - 0x18], %g1
fib_array[i] = prev_number + curr_number
curr_number(%g1) = prev_number(%o5) + curr_number(%g1)
fibonacci+0x78: add %o5, %g1, %g1
fib_array[i] = curr_number(%g1)
fibonacci+0x7c: st %g1, [%o3 + %o4]
prev_number = curr_number
{
[%fp - 0x18] = curr_number
fibonacci+0x80: ld [%fp - 0x18], %g1
[%fp - 0x14] = prev_number
fibonacci+0x84: st %g1, [%fp - 0x14]
}
fibonacci+0x88: sethi %hi(0x20c00), %g1
fibonacci+0x8c: or %g1, 0x340, %o5
g1 = i
fibonacci+0x90: ld [%fp - 0x1c], %g1
%o4 = %g1 * 2
shift left logic
fibonacci+0x94: sll %g1, 0x2, %g1
curr_number = fib_array[i];
{
%o5 = fib_array;
fib_array[i] = %g1
fibonacci+0x98: ld [%o5 + %g1], %g1
[%fp - 0x18] = %g1 = curr_number
fibonacci+0x9c: st %g1, [%fp - 0x18]
}
[%fp - 0x1c] = %g1 = i
fibonacci+0xa0: ld [%fp - 0x1c], %g1
i ++
fibonacci+0xa4: add %g1, 0x1, %g1
fibonacci+0xa8: st %g1, [%fp - 0x1c]
branch always
fibonacci+0xac: ba -0x60
fibonacci+0xb0: nop
return(fib_array);
fibonacci+0xb4: sethi %hi(0x20c00), %g1
fibonacci+0xb8: or %g1, 0x340, %g1
fibonacci+0xbc: mov %g1, %i0
fibonacci+0xc0: ret
fibonacci+0xc4: restore
> $q
References:
[1]
[2] ~psm/sparcstack.html