York Jong's Library tagged → View Popular
22 Nov 08
一个有趣的关于C宏的题目及巧解
定義一個C宏,實現插入0~255個NOP指令
-
//宏定义方法:
#define __NOP1__ asm("nop");
#define __NOP2__ __NOP1__ __NOP1__
#define __NOP4__ __NOP2__ __NOP2__
#define __NOP8__ __NOP4__ __NOP4__
#define __NOP16__ __NOP8__ __NOP8__
#define __NOP32__ __NOP16__ __NOP16__
#define __NOP64__ __NOP32__ __NOP32__
#define __NOP128__ __NOP64__ __NOP64__
#define __NOPX__(a) \
if ((a)&(0x01)) {__NOP1__} \
if ((a)&(0x02)) {__NOP2__} \
if ((a)&(0x04)) {__NOP4__} \
if ((a)&(0x08)) {__NOP8__} \
if ((a)&(0x10)) {__NOP16__} \
if ((a)&(0x20)) {__NOP32__} \
if ((a)&(0x40)) {__NOP64__} \
if ((a)&(0x80)) {__NOP128__}
//宏引用方法(举例):
__NOPX__(13)
//编译结果:
138: __NOPX__(13)
051D 0000 NOP
051E 0000 NOP
051F 0000 NOP
0520 0000 NOP
0521 0000 NOP
0522 0000 NOP
0523 0000 NOP
0524 0000 NOP
0525 0000 NOP
0526 0000 NOP
0527 0000 NOP
0528 0000 NOP
0529 0000 NOP
29 Mar 08
C语言的宏定义--匠人的百宝箱
-
3,得到指定地址上的一个字节或字
#define MEM_B( x ) ( *( (byte *) (x) ) )
#define MEM_W( x ) ( *( (word *) (x) ) )
-
6,得到一个结构体中field所占用的字节数
#define FSIZ( type, field ) sizeof( ((type *) 0)->field )
> - 5 more annotations...
10 Feb 08
一個常用於設定Register的macro - GaryLee
-
- REG_ADDR
- REG_VALUE
在為數不少硬體中,要存取其內部的register可能需要透過I/O port的方式進行。舉例來說,如果有兩個I/O port分別為
- REG_ADDR
-
#define REG(_reg_) *(REG_ADDR = (_reg_), ®_VALUE)
1 - 5 of 5
Showing 20▼ items per page
Sponsored Links
Ads by Google
Top Contributors
Groups interested in macro
Related Lists on Diigo
-
Economic Crisis
News, trends, and expectati...
Items: 8 | Visits: 1
Created by: Luis Arcadio De Jesus R.
-
Macro1
Interesting readings relate...
Items: 1 | Visits: 1
Created by: pippo_pippo
-
Macro lenses
Items: 31 | Visits: 2
Created by: Luis Gracia
Diigo is about better ways to research, share and collaborate on information. Learn more »
Join Diigo
