I want to implement a private longjmp to return quickly from subroutines to the top routine in our embedded system. My code looks like this: ---------------------------------------------- int top_routine() { { int reg0; __asm__ __volatile__( "la %0, QUIT\n\t" "sw %0, %1\n\t" "sw $29,%2\n\t": "=r"(reg0), "=m"(quit_addr.ra), "=m"(quit_addr.sp) ); } ... sub_routine(); ... __asm__ __volatile__("QUIT:\n\t"); write_reg32(mask, 0xb0020004); ... return 0; } ---------------------------------------------- Before returning, there are some cleaning work to be done (The code following the label QUIT). Here I get some problems. On -O2 optimization, gcc may save the value in a register like s8, and won't reload it again from stack for this statement: write_reg32(mask, 0xb0020004); The registers may be changed during calling to subroutines so that the cleaning work can't be done properly and the top routine can't quit normally. It is a solution to declare the variable `mask' volatile. But it is not a general approach. Is there a way to inform gcc not to do optimization just from the lable QUIT to the end of top_routine. Or is there another better way to implement longjmp? Best Regards, PRC Apr 22, 2008