/* sparc assembly to compute n!, n stored in %i0 */ .global main .align 4 str0: .asciz "the value of 6! is %d\n" .align 4 ! align next inst on 32 bit boundary. main: /* use %o0 as accumulator */ mov 1,%o0 mov 6,%i0 ! want 6! mullp: cmp %i0,2 bl basecase nop ! pipeline delay slot mov %i0,%o1 ! prepare for function call call .mul nop ba mullp dec %i0 ! fills pipeline delay slot with useful operation basecase: /* at this point o0 has value */ /* to call printf o0 has to hold str0 address, value to print has to be o1 */ mov %o0,%o1 mov 0,%o0 sethi %hi(str0),%o2 ! loads high 22bits of str0 to o2 or %o2,%lo(str0),%o0 ! add in low order 10 bits ! set str0,%o0 ! macro for above 2 instructions call printf nop mov 1, %g1 ta 0 ! trap to OS