; generated by Component: ARM Compiler 5.04 update 1 (build 49) Tool: ArmCC [5040049]
; commandline ArmCC [--list --split_sections --debug -c --asm --interleave -o.\obj\coreutilitylib.o --asm_dir=.\lst\ --list_dir=.\lst\ --depend=.\obj\coreutilitylib.d --cpu=Cortex-M0 --apcs=interwork -I..\..\..\..\Library\CMSIS\Include -I..\..\..\..\Library\Device\Nuvoton\NM1120\Include -I..\..\..\..\Library\StdDriver\inc -I.\source -IC:\Keil_v5\ARM\RV31\INC -IC:\Keil_v5\ARM\PACK\ARM\CMSIS\3.20.4\CMSIS\Include -D__MICROLIB --omf_browse=.\obj\coreutilitylib.crf source\CoreUtilityLib.c]
                          THUMB

                          AREA ||i.AddWithoutOverflowUInt16||, CODE, READONLY, ALIGN=2

                  AddWithoutOverflowUInt16 PROC
;;;85     *******************************************************************************/
;;;86     TSWord AddWithoutOverflowUInt16(const TSWord a_i16A, const TSWord a_i16B)
000000  1842              ADDS     r2,r0,r1
;;;87     {
;;;88        TSWord i16Result;
;;;89     
;;;90        // Calculate first, if this value overflows, it will be overridden
;;;91        // below.  Otherwise, it will be returned.
;;;92        i16Result = a_i16A + a_i16B;
;;;93     
;;;94        // If negative protect against overflowing the MIN_INT16
;;;95        if ((a_i16A < 0) && (a_i16B < 0))
000002  2800              CMP      r0,#0
000004  da06              BGE      |L1.20|
000006  2900              CMP      r1,#0
000008  da0e              BGE      |L1.40|
;;;96        {
;;;97           // If there isn't room to add the second value, set to MIN
;;;98           if ((MIN_INT16 - a_i16A) > a_i16B)
00000a  4b08              LDR      r3,|L1.44|
00000c  1a18              SUBS     r0,r3,r0
00000e  4288              CMP      r0,r1
000010  dc09              BGT      |L1.38|
000012  e009              B        |L1.40|
                  |L1.20|
;;;99           {
;;;100             i16Result = MIN_INT16;
;;;101          }
;;;102       }
;;;103       // If positive protect against overflowing the MAX_INT16
;;;104       else if ((a_i16A > 0) && (a_i16B > 0))
000014  2800              CMP      r0,#0
000016  dd07              BLE      |L1.40|
000018  2900              CMP      r1,#0
00001a  dd05              BLE      |L1.40|
;;;105       {
;;;106          // If there isn't room to add the second value, set to MAX
;;;107          if ((MAX_INT16 - a_i16A) < a_i16B)
00001c  4b03              LDR      r3,|L1.44|
00001e  43db              MVNS     r3,r3
000020  1a18              SUBS     r0,r3,r0
000022  4288              CMP      r0,r1
000024  da00              BGE      |L1.40|
                  |L1.38|
;;;108          {
;;;109             i16Result = MAX_INT16;
000026  461a              MOV      r2,r3
                  |L1.40|
;;;110          }
;;;111       }
;;;112       // Otherwise, use the original value.
;;;113    
;;;114       return(i16Result);
000028  4610              MOV      r0,r2
;;;115    }
00002a  4770              BX       lr
;;;116    
                          ENDP

                  |L1.44|
                          DCD      0xffff8000

                          AREA ||i.Core_UtilityLib_2ToThePower||, CODE, READONLY, ALIGN=1

                  Core_UtilityLib_2ToThePower PROC
;;;39     *******************************************************************************/
;;;40      TWord Core_UtilityLib_2ToThePower(const TByte a_u8Power)
000000  2101              MOVS     r1,#1
;;;41     {
;;;42        return((TWord)0x0001 << (TWord)a_u8Power);
000002  4081              LSLS     r1,r1,r0
000004  4608              MOV      r0,r1
;;;43     }
000006  4770              BX       lr
;;;44     
                          ENDP


                          AREA ||i.Core_UtilityLib_AddWithoutOverflowUInt16||, CODE, READONLY, ALIGN=2

                  Core_UtilityLib_AddWithoutOverflowUInt16 PROC
;;;131    *******************************************************************************/
;;;132    TWord Core_UtilityLib_AddWithoutOverflowUInt16(TWord a_u16A, TWord a_u16B)
000000  4602              MOV      r2,r0
;;;133    {
;;;134       TWord u16Result;
;;;135    
;;;136       // Calculate first, if this value overflows, it will be overridden
;;;137       // below.  Otherwise, it will be returned.
;;;138       u16Result = a_u16A + a_u16B;
;;;139    
;;;140       // Values are both positive, protect against overflowing the MAX_UINT16
;;;141       // If there isn't room to add the second value, set to MAX
;;;142       if ((MAX_UINT16 - a_u16A) < a_u16B)
000002  4b03              LDR      r3,|L3.16|
000004  1840              ADDS     r0,r0,r1              ;138
000006  1a9a              SUBS     r2,r3,r2
000008  428a              CMP      r2,r1
00000a  d200              BCS      |L3.14|
;;;143       {
;;;144          u16Result = MAX_UINT16;
00000c  4618              MOV      r0,r3
                  |L3.14|
;;;145       }
;;;146       // Otherwise, use the original value.
;;;147    
;;;148       return(u16Result);
;;;149    }
00000e  4770              BX       lr
;;;150    
                          ENDP

                  |L3.16|
                          DCD      0x0000ffff

                          AREA ||i.Core_UtilityLib_InitAverage||, CODE, READONLY, ALIGN=1

                  Core_UtilityLib_InitAverage PROC
;;;166    *************************************************************************/
;;;167    void Core_UtilityLib_InitAverage(TSAverageItem* a_psAverage,TByte u8SampleSize)
000000  2200              MOVS     r2,#0
;;;168    {
;;;169    	//Initialize the structure 
;;;170    	a_psAverage->u16Average = 0;
;;;171    	a_psAverage->u32Sum = 0;
000002  6082              STR      r2,[r0,#8]
;;;172    	a_psAverage->u8SampleSize = u8SampleSize;
000004  6002              STR      r2,[r0,#0]
000006  7101              STRB     r1,[r0,#4]
;;;173    	a_psAverage->u8SamplesTaken = 0;
000008  7142              STRB     r2,[r0,#5]
;;;174    }
00000a  4770              BX       lr
;;;175    
                          ENDP


                          AREA ||i.GetAverageValue||, CODE, READONLY, ALIGN=1

                  GetAverageValue PROC
;;;51     **************************************************************************************/
;;;52     TWord GetAverageValue( TWord* pwDataBuf,TByte urDataNum )
000000  4603              MOV      r3,r0
;;;53     {
000002  b510              PUSH     {r4,lr}
;;;54        TByte i;
;;;55        TWord uwSum;
;;;56        TWord uwReturnValue;
;;;57        //Clear the sum
;;;58        uwSum = 0;
000004  2000              MOVS     r0,#0
;;;59        //We need to calculate the average
;;;60        for(i = 0; i<urDataNum; i++)
000006  4602              MOV      r2,r0
000008  e004              B        |L5.20|
                  |L5.10|
;;;61           {
;;;62           //Add this value to the sum
;;;63           uwSum += pwDataBuf[i];
00000a  0094              LSLS     r4,r2,#2
00000c  591c              LDR      r4,[r3,r4]
00000e  1820              ADDS     r0,r4,r0
000010  1c52              ADDS     r2,r2,#1
000012  b2d2              UXTB     r2,r2                 ;60
                  |L5.20|
000014  428a              CMP      r2,r1                 ;60
000016  d3f8              BCC      |L5.10|
;;;64           }
;;;65        //Now that we have the sum, calculate the average
;;;66        uwReturnValue = (TWord)(uwSum/(urDataNum));
000018  f7fffffe          BL       __aeabi_uidivmod
;;;67        return (uwReturnValue);
;;;68     }
00001c  bd10              POP      {r4,pc}
;;;69     
                          ENDP

