Showing results for 
Search instead for 
Did you mean: 

PSoC 5, 3 & 1 MCU

Not applicable

Hi All,


Many of you may not be aware of what saturation instructions do in PSoC 5LP. PSoC 5LP uses Cortex-M3 core which has two special instructions called "SSAT" (Signed saturation) and "USAT" (Unsigned saturation). These instructions are used to limit a variable or a value to a certain number of bits. (Reference:


For example,  if you have an 8 bit variable and for sure if you know that the value of the variable will not exceed a number 127 say, you would like to round off any value above 127 as 127 itself ( saturation) and any value below 0 as zero itself. In this case you need to write a big C code using if-else conditional statement to compare the variable with 127 and take the necessary action. Instead, to simplify this logic, you can make use of the saturation assembly instructions which Cortex-M3 (core of PSoC 5LP) supports. Please note that both GCC and MDK compilers do not append this instruction by itself for an equivalent C code.


For example, in the above example, the number of bits to restrict my result to would be 7 (2^7-1 = 127). Assuming I have the unsaturated value in register r0 and if I would like to store the saturated result in register r3, my assembly instruction would be


"usat r3, 8, r0"


Similar syntax is for signed saturation for specifying a positive limit and a negative limit for a signed variable. I hope you know the syntax to include an assembly instruction in C code.








FYI, if you would like to assign a variable to a particular register, the syntax is "register (data type)* variable_name asm("register name");"


For example: register uint8* output asm ("r0");

1 Solution
Not applicable

 Just adding one more point on the usage of saturation instruction based on the compiler- (GCC or MDK )


While using GCC compiler, as mentioned above, we need to use the registers. eg: asm(“USAT r3,8,r0");


So first  we need to store the variables that will contain the unsaturated and saturated results using the syntax given in the first post.


However, for MDK compilers you can directly use the local variables along with this instruction and there is no need to specify the registers:


eg: __asm(“ssat data_sat,8,data_unsat");




PSoC Wonders



View solution in original post

10 Replies