lowbit 计算最低位的1
int lowbit(int x){
return x & (-x);
}
offset 结构体成员在结构体中的偏移量
#define offset(TYPE, MEMBER) ((long) & ((TYPE * )0) -> MEMBER)
得到一个结构体中field所占用的字节数
#define FSIZ( type, field ) sizeof( ((type *) 0)->field )
得到上一个地址上的一个字节或字
#define MEM_B( x ) ( *( (byte *) (x) ) )
#define MEM_W( x ) ( *( (word *) (x) ) )
得到一个字的高位和低位字节
#define WORD_LO(xxx) ((byte) ((word)(xxx) & 255))
#define WORD_HI(xxx) ((byte) ((word)(xxx) >> 8))
返回一个比x大的最接近的8的倍数
#define RND8(x) ((((x) + 7) / 8) * 8)
判断字符是不是10进制的数字
#define DECCHK( c ) ((c) >= '0' && (c) <= '9')
判断字符是不是16进制的数字
#define HEXCHK( c ) ( ((c) >= '0' && (c) <= '9') ||\
((c) >= 'A' && (c) <= 'F') ||\
((c) >= 'a' && (c) <= 'f') )
防止溢出的一个方法
#define INC_SAT( val ) (val = ((val)+1 > (val)) ? (val)+1 : (val))
返回数组元素的个数
#define ARR_SIZE(a) (sizeof((a)) / sizeof((a[0])))
返回一个无符号数n尾的值MOD_BY_POWER_OF_TWO(X,n)=X%(2^n)
#define MOD_BY_POWER_OF_TWO(val, mod_by) ((dword)(val) & (dword)((mod_by)-1))
对于IO空间映射映射在存储空间的结构,输入输出处理
#define inp(port) (*((volatile byte *) (port)))
#define inpw(port) (*((volatile word *) (port)))
#define inpdw(port) (*((volatile dword *)(port)))
#define outp(port, val) (*((volatile byte *) (port)) = ((byte) (val)))
#define outpw(port, val) (*((volatile word *) (port)) = ((word) (val)))
#define outpdw(port, val) (*((volatile dword *) (port)) = ((dword) (val)))