Nios/saturate
From ASMBits
nios/extendPrevious
Nextnios/saturate2
Sometimes when doing arithmetic, it is better to "saturate" (or clamp) numbers that overflow to the maximum possible value rather than wrap around.
Write a function that will convert an unsigned 32-bit number to 16 bits. If the 32-bit number is too big to fit, saturate (or clamp) the output to the maximum possible unsigned 16-bit value.
unsigned short saturate(unsigned int n);
Sample Input
0x12345
Sample Output
0xffff
nios/extendPrevious
Nextnios/saturate2