write stack_fsm