开发者

can anyone help me with this macro?

Anyone can explain in details what the following macro does?

#define write_XDATA(address,value) (((char *)0x010000) [address]开发者_开发知识库=value)

thx!


You use it:

write_XDATA( Address, Value );

and it is expanded:

((char*)0x010000)[Address]=Value;

which is equivalent to the following:

char* baseAddress = (char*)0x010000;
*(baseAddress + Address) = Value;

so basically it writes a byte stored in Value at the address 0x010000 + Address.


It assigns value to the byte at memory location 0x10000 + address. It's easier to grok if you separate it out a bit:

char* buf = (char *)0x010000;
buf[address]=value;

(Though of course you have no choice but to mash it all together in a macro.)


That's most probably part of a program designed to run on an embedded platform. It's used to do memory mapped IO.

The base address of the register-map is 0x010000. It writes value to the memory location 0x010000+address.

The use of the square brackets [] works because of the equivalence of array-addressing and pointer arithmetic in C.


It maps addresses to real addresses using an offset and then writes to it. XDATA is probably a term taken over from the 8051-processor.


I don't know how much details you want to hear, but the macro expands itself to what you have just written -

macro parameters address and value are put into address and value placeholders in the macro expansion definition (((char *)0x010000) [address]=value)


This macro on address + 0x010000 saving one byte of value.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜