Shell Script Bitwise operation +FOR Loop + return value to undertake

Source: Internet
Author: User
Tags bitwise

Implementing a certain bit of a register with a shell script

Pit bit 1:

Not recognized on the Development Board (Ubuntu can)

For ((i=0;i<6;i++))

Do

Done

Into:

For i in ' seq 0 6 '

Do

Done

Pit bit 2:

return value by default only 8 bits are truncated.

Setbits $  $4
Regv=$?
printf "regv=% #x \ n" $REGV

Found only eight low-bits left.


So, change the type of undertaking:
regv= ' RegRead $ '
This is done by directly executing the command or outputting something on the screen, which is the string.

Pit bit 3:

As above, reg= ' RegRead $ ' gets the string if it is not printed with printf "%d", the direct echo line

Pit bit 4:

Reg=setbits $ $4 This way to take a pop grammar error, not C language.

The final test was successful, as follows:

####################################################### # test the SAR-ADC I N SOC ##########################################                                                                                                                                                   #############                                                                                           RegWrite ()                                                                                                            {                                                                                                                                                  Devmem $32}                                                                                  RegRead ()          {Dev                                                                                                                                                         MEM $}                                                                               # #argv [1]: Origin data                                                                                 # #argv [2]: Start bit # #argv [3]: End bit # #argv [4]: ResU                                                                                            Lt Setbits ()                                                                                {                            Value=$1                                                                                                           For i in ' seq $ $ ' do                                                                                 mask=$ ((0x1 << $i))                                                                         #printf "mask =% #x \ n" $mask                                                                         value=$ (($value & ~ $mask))                                                       #printf "clean bit%d value =% #x \ n" $i $value                                                                        mask1=$ ((0x1 << ($i-$))) #printf "Mask1 =% #x \ n" $mask 1 bitv=$ ($4 &am P             MASK1))                                                                  #printf "BITV =% #x \ n" $bitv value=$ ($value |                                                                 ($bitv << $)))                                                                                                         #printf "Set bit%d value =% #x \ n" $i $value done                                                                                printf "% #x \ n" $value                                                                        return $value                                                                                                                                                                                                                             }                     Reg_set_bits ()                                                                  {                                                                                    regv= ' RegRead $ '                                                                       regv= ' setbits $REGV $ $4 '                                                                                                                                           RegWrite $ $REGV}    Reg_set_bits $ $4

  

Shell Script Bitwise operation +FOR Loop + return value to undertake

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.