一个设置寄存器值的应用示例

#include 
#include 
int main(int argc,char *argv[])
{
    int i = 0;
    if(argc != 4) {
        printf("usage : regAddr bit value");
        return -1;
    }
    for(i=0;i<4;i++){
        printf("%s ",argv[i]);
    }
    printf("\n");
    unsigned int reg_addr = strtol(argv[1],NULL,16);
    unsigned int bit = strtol(argv[2],NULL,10);
    unsigned int value = strtol(argv[3],NULL,10);
    printf("register:0x%x\t",reg_addr);
    printf("bit:%d\t",bit);
    printf("value:%d\n",value);
    printf("------------------\n");
    if(value == 0){
        printf("clear bit\n");
        reg_addr &=~(1<

程序代码如上,测试方法如下:

(1)置位

$ gcc bit_ctrl.c -o bit_ctrl  && ./bit_ctrl 0 31 1
./bit_ctrl 0 31 1
register:0x0    bit:31  value:1
------------------
set bit
register:0x80000000

(2)清零
$ gcc bit_ctrl.c -o bit_ctrl  && ./bit_ctrl FFFFFFFF 31 0
./bit_ctrl FFFFFFFF 31 0
register:0xffffffff     bit:31  value:0
------------------
clear bit
register:0x7fffffff
 

你可能感兴趣的:(Linux/Unix)