Keil Logo

C166: Performing a Software Reset in C

Information in this article applies to:

  • C166 All Versions


I need to perform a software reset in C without using inline assembly. How can I do that?


There are 2 ways to accomplish this depending on what you want to achieve:

  1. The following reset function jumps to 0 and starts executing code from there. Note that since this is only jumping to the reset vector, the chip is not actually being reset. The startup code (executed before EINIT) will have no effect.

    void reset (void)
    ((void (far *) (void)) 0x000000) ();

    The following code is generated for the reset function. The ?C_SCALLI routine calls the address stored in R4 and R5 (which is 0x000000).

    0000 E004          MOV       R4,#00H
    0002 E005          MOV       R5,#00H
    0004 DA000000 E    CALLS     SEG (?C_SCALLI),?C_SCALLI
    0008 CB00          RET
  2. The Keil compiler supports a number of "intrinsic library functions". These are not really functions. When you use one of them, the compiler inserts a C16x architecture specific instruction inline. You do not need to use the "asm" pragma and you don't need to insert assembly mnemonics yourself.

    To perform a software reset, use intrinsic library function _trap_ with a parameter of 0. For example:

    // ...............................
      _trap_ (0);

    If you look at the listing file, you will see that main function has an SRST assembly instruction in place of _trap_(0).


  • Refer to _trap_ in the C166 User's Guide.


Last Reviewed: Thursday, February 25, 2021

Did this article provide the answer you needed?
Not Sure
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.