//#include
#define p(...) printf(__VA_ARGS__)
typedef struct xxx_reg{
unsigned long reg1;
unsigned long reg2;
unsigned long reg3;
unsigned long reg4;
unsigned long reg5;
unsigned long reg6;
unsigned long reg7;
unsigned long reg8;
unsigned long reg9;
unsigned long reg10;
unsigned long reg11;
}xxx_reg_t1,xxx_reg_t2; /*struct xxx_reg,xxx_reg_t1,xxx_reg_t2三个可以通用,害的我半天没有编译通过
这个技巧用来对那些长度不等的寄存器进行寻址和操作,
可以省去一堆的 #define REG1 *(volatile unsigned long *)0x30008000*/
struct xxx_reg_t *sp = (struct xxx_reg_t *)0x30008000;
int main(void)
{
//sp->reg1 = 0x12121212;
p("%x\n",(&sp->reg1));
p("%x\n",(&sp->reg1));
p("%x\n",(&sp->reg2));
p("%x\n",(&sp->reg3));
p("%x\n",(&sp->reg4));
p("%x\n",(&sp->reg5));
p("%x\n",(&sp->reg6));
p("%x\n",(&sp->reg7));
p("%x\n",(&sp->reg8));
p("%x\n",(&sp->reg9));
p("%x\n",(&sp->reg10));
p("%x\n",(&sp->reg11));
sp->reg1 &= ~(1<<11); /*没有os就不会报错了*/
return 0;
}
运行结果:
lzd@lzd-laptop:~/c_test$ ./a.out
30008000
30008000
30008004
30008008
3000800c
30008010
30008014
30008018
3000801c
30008020
30008024
30008028
Segmentation fault
lzd@lzd-laptop:~/c_test$
阅读(1098) | 评论(0) | 转发(0) |