VARS VAR N CODE st 40,[N] ENDCODE VAR I CODE st 0,[I] ENDCODE VAR fibbs CODE ld [N],%t2 cmp %t2,0 bge L0 mov 0,%t2 L0: mov 1,%t0 add %t0,%t2,%t0 st %t0,[$a0] call PCAT$alloc add %o0,%t0,%t1 sub %t1,%t2,%t3 L1: cmp %t1,%t3 ble L2 dec %t1 st 0,[%t1] ba L1 L2: dec %t0 st %t0,[%o0] st %t1,[fibbs] ENDCODE VAR j CODE st 0,[j] ENDCODE VAR n CODE st 0,[n] ENDCODE PROCS PROC init ( a ) VARS VAR i CODE st 2,[i] ENDCODE CODE cmp 0,0 bge L0 call PCAT$bounds_error L0: ld [a],%t0 sub %t0,1,%t1 ld [%t1],%t1 cmp 0,%t1 bl L1 call PCAT$bounds_error L1: add %t0,0,%t0 st 1,[%t0] cmp 1,0 bge L2 call PCAT$bounds_error L2: ld [a],%t2 sub %t2,1,%t3 ld [%t3],%t3 cmp 1,%t3 bl L3 call PCAT$bounds_error L3: add %t2,1,%t2 st 1,[%t2] L4: ld [i],%t4 ld [N],%t5 sub %t5,1,%t6 cmp %t4,%t6 bl L5 ba L6 L5: ld [i],%t7 cmp %t7,0 bge L7 call PCAT$bounds_error L7: ld [a],%t8 sub %t8,1,%t9 ld [%t9],%t9 cmp %t7,%t9 bl L8 call PCAT$bounds_error L8: add %t8,%t7,%t8 ld [I],%t10 st %t10,[%t8] ld [i],%t11 add %t11,1,%t12 st %t12,[i] ba L4 L6: return ENDCODE PROCS PROC fibb ( i ) CODE ld [i],%t1 cmp %t1,0 bge L3 call PCAT$bounds_error L3: ld [fibbs],%t2 sub %t2,1,%t3 ld [%t3],%t3 cmp %t1,%t3 bl L4 call PCAT$bounds_error L4: add %t2,%t1,%t2 ld [%t2],%t0 ld [I],%t4 cmp %t0,%t4 be L0 ba L1 L0: ld [i],%t5 cmp %t5,0 bge L5 call PCAT$bounds_error L5: ld [fibbs],%t6 sub %t6,1,%t7 ld [%t7],%t7 cmp %t5,%t7 bl L6 call PCAT$bounds_error L6: add %t6,%t5,%t6 ld [i],%t9 sub %t9,2,%t10 st %t10,[$a0] call fibb mov %o0,%t8 ld [i],%t12 sub %t12,1,%t13 st %t13,[$a0] call fibb mov %o0,%t11 add %t8,%t11,%t14 st %t14,[%t6] ba L2 L1: L2: ld [i],%t16 cmp %t16,0 bge L7 call PCAT$bounds_error L7: ld [fibbs],%t17 sub %t17,1,%t18 ld [%t18],%t18 cmp %t16,%t18 bl L8 call PCAT$bounds_error L8: add %t17,%t16,%t17 ld [%t17],%t15 mov %t15,%i0 return return ENDCODE CODE ld [fibbs],%t4 st %t4,[$a0] call init st "Enter indices of eight fibbonacci numbers:",[$a0] call PCAT$write_string call PCAT$write_newline L3: ld [j],%t5 cmp %t5,8 bl L4 ba L5 L4: call PCAT$read_int st %o0,[n] ld [n],%t6 ld [N],%t7 cmp %t6,%t7 bg L6 ba L7 L6: st "Maximum index is ",[$a0] call PCAT$write_string ld [N],%t8 st %t8,[$a0] call PCAT$write_int call PCAT$write_newline ba L8 L7: ld [n],%t9 st %t9,[$a0] call PCAT$write_int st " ",[$a0] call PCAT$write_string ld [n],%t11 st %t11,[$a0] call fibb mov %o0,%t10 st %t10,[$a0] call PCAT$write_int call PCAT$write_newline L8: ld [j],%t12 add %t12,1,%t13 st %t13,[j] ba L3 L5: return ENDCODE