/* hand written assembly to test function calls */ .global main .global f .align 4 .str0: .asciz "The value of COUNTER is now %d\n" .align 4 f: ! void f(int n) save %sp,-112,%sp ! register window shift st %i0,[%fp-4] ! save param as local var sethi %hi(.str0),%o0 ! ^ don't use [fp-0] !!! or %o0,%lo(.str0),%o0 ! printf string ld [%fp-4],%o1 ! second param to printf call printf nop ret ! reset pc restore ! safely occupies delay slot main: mov 1,%l1 ! loop counter loop: cmp %l1,10 bg quit mov %l1,%o0 call f add %l1,1,%l1 ! delay slot filled! ba loop nop quit: mov 1,%g1 ! trap to os ta 0 ret ! caused Segmentation fault restore