VARS VAR N CODE st 10,[N] ENDCODE VARS VAR a 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,[a] ENDCODE PROCS PROC quicksort ( a m n ) VARS VAR i CODE st 0,[i] ENDCODE PROCS PROC partition ( y z ) VARS VAR i CODE ld [y],%t0 st %t0,[i] ENDCODE VAR j CODE ld [z],%t1 add %t1,1,%t2 st %t2,[j] ENDCODE PROCS PROC meet ( ) PROCS PROC up ( ) CODE ld [i],%t0 add %t0,1,%t1 st %t1,[i] ld [i],%t3 cmp %t3,0 bge L3 call PCAT$bounds_error L3: ld [a],%t4 sub %t4,1,%t5 ld [%t5],%t5 cmp %t3,%t5 bl L4 call PCAT$bounds_error L4: add %t4,%t3,%t4 ld [%t4],%t2 ld [y],%t7 cmp %t7,0 bge L5 call PCAT$bounds_error L5: ld [a],%t8 sub %t8,1,%t9 ld [%t9],%t9 cmp %t7,%t9 bl L6 call PCAT$bounds_error L6: add %t8,%t7,%t8 ld [%t8],%t6 cmp %t2,%t6 bl L0 ba L1 L0: call up ba L2 L1: L2: return ENDCODE PROCS PROC down ( ) CODE ld [j],%t0 sub %t0,1,%t1 st %t1,[j] ld [j],%t3 cmp %t3,0 bge L3 call PCAT$bounds_error L3: ld [a],%t4 sub %t4,1,%t5 ld [%t5],%t5 cmp %t3,%t5 bl L4 call PCAT$bounds_error L4: add %t4,%t3,%t4 ld [%t4],%t2 ld [y],%t7 cmp %t7,0 bge L5 call PCAT$bounds_error L5: ld [a],%t8 sub %t8,1,%t9 ld [%t9],%t9 cmp %t7,%t9 bl L6 call PCAT$bounds_error L6: add %t8,%t7,%t8 ld [%t8],%t6 cmp %t2,%t6 bg L0 ba L1 L0: call down ba L2 L1: L2: return ENDCODE CODE ld [i],%t0 ld [j],%t1 cmp %t0,%t1 bl L0 ba L1 L0: call up call down ld [i],%t2 ld [j],%t3 cmp %t2,%t3 bl L3 ba L4 L3: ld [i],%t4 ld [j],%t5 st %t5,[$a1] st %t4,[$a0] call exchange ba L5 L4: L5: call meet ba L2 L1: L2: return ENDCODE CODE call meet ld [y],%t3 ld [j],%t4 st %t4,[$a1] st %t3,[$a0] call exchange ld [j],%t5 mov %t5,%i0 return return ENDCODE PROC exchange ( p q ) VARS VAR x CODE ld [p],%t1 cmp %t1,0 bge L0 call PCAT$bounds_error L0: ld [a],%t2 sub %t2,1,%t3 ld [%t3],%t3 cmp %t1,%t3 bl L1 call PCAT$bounds_error L1: add %t2,%t1,%t2 ld [%t2],%t0 st %t0,[x] ENDCODE CODE ld [p],%t4 cmp %t4,0 bge L2 call PCAT$bounds_error L2: ld [a],%t5 sub %t5,1,%t6 ld [%t6],%t6 cmp %t4,%t6 bl L3 call PCAT$bounds_error L3: add %t5,%t4,%t5 ld [q],%t8 cmp %t8,0 bge L4 call PCAT$bounds_error L4: ld [a],%t9 sub %t9,1,%t10 ld [%t10],%t10 cmp %t8,%t10 bl L5 call PCAT$bounds_error L5: add %t9,%t8,%t9 ld [%t9],%t7 st %t7,[%t5] ld [q],%t11 cmp %t11,0 bge L6 call PCAT$bounds_error L6: ld [a],%t12 sub %t12,1,%t13 ld [%t13],%t13 cmp %t11,%t13 bl L7 call PCAT$bounds_error L7: add %t12,%t11,%t12 ld [x],%t14 st %t14,[%t12] return ENDCODE CODE ld [n],%t0 ld [m],%t1 cmp %t0,%t1 bg L0 ba L1 L0: ld [m],%t3 ld [n],%t4 st %t4,[$a1] st %t3,[$a0] call partition mov %o0,%t2 st %t2,[i] ld [a],%t5 ld [m],%t6 ld [i],%t7 sub %t7,1,%t8 st %t8,[$a2] st %t6,[$a1] st %t5,[$a0] call quicksort ld [a],%t9 ld [i],%t10 add %t10,1,%t11 ld [n],%t12 st %t12,[$a2] st %t11,[$a1] st %t9,[$a0] call quicksort ba L2 L1: L2: return ENDCODE PROCS PROC readarray ( ) VARS VAR i CODE st 0,[i] ENDCODE CODE L0: ld [i],%t0 ld [N],%t1 sub %t1,1,%t2 cmp %t0,%t2 bl L1 ba L2 L1: ld [i],%t3 cmp %t3,0 bge L3 call PCAT$bounds_error L3: ld [a],%t4 sub %t4,1,%t5 ld [%t5],%t5 cmp %t3,%t5 bl L4 call PCAT$bounds_error L4: add %t4,%t3,%t4 call PCAT$read_int st %o0,[%t4] ld [i],%t6 add %t6,1,%t7 st %t7,[i] ba L0 L2: ld [i],%t8 cmp %t8,0 bge L5 call PCAT$bounds_error L5: ld [a],%t9 sub %t9,1,%t10 ld [%t10],%t10 cmp %t8,%t10 bl L6 call PCAT$bounds_error L6: add %t9,%t8,%t9 neg 1000,%t11 st %t11,[%t9] return ENDCODE PROCS PROC writearray ( ) VARS VAR i CODE st 0,[i] ENDCODE CODE L0: ld [i],%t0 ld [N],%t1 sub %t1,1,%t2 cmp %t0,%t2 bl L1 ba L2 L1: ld [i],%t4 cmp %t4,0 bge L3 call PCAT$bounds_error L3: ld [a],%t5 sub %t5,1,%t6 ld [%t6],%t6 cmp %t4,%t6 bl L4 call PCAT$bounds_error L4: add %t5,%t4,%t5 ld [%t5],%t3 st %t3,[$a0] call PCAT$write_int call PCAT$write_newline ld [i],%t7 add %t7,1,%t8 st %t8,[i] ba L0 L2: return ENDCODE CODE call readarray ld [a],%t4 ld [N],%t5 sub %t5,2,%t6 st %t6,[$a2] st 0,[$a1] st %t4,[$a0] call quicksort call writearray return ENDCODE