In <bdc3br$ppq$> "John T." <> writes:
>First, could I address some bit of an unsigned integer? lets say the integer
>"mrtest" holds the value 0xFFFF0000 and I would like to do something like
>(this is wirtten in some pseudo code)
>if(mrtest(bit7,bit6,bit5,bit4 and bit 3 == 0b00000)
>{
>do a lot of things;
>}
Try to use some kind of pseudo code that makes sense to other people, too.
If you want to test that all these bits are 0, build an unsigned mask
containing ones only in the corresponding positions: 0xF8U should do the
job (assumming bit0 is the least significant one). A bitwise and between
the value to be tested and the mask will tell you if all the relevant
bits are zero:
if ((mrtest & 0xF8U) == 0) {
/* do a lot of things */ ;
}
The extra pair of parentheses is needed because the & operator has the
"wrong" precedence WRT the == operator.
>Second, how do I store a variable at a specific address?
>for example
>Store mrtest at address 0xFFFF1166.
This is a very unwise thing to do, unless you have a *good* reason for
doing it. Most modern platforms use virtual memory, which makes such
an exercise pointless.
The answer is to define mrtest as a macro:
#define mrtest (*(unsigned int *)0xFFFF1166)
Now, the identifier mrtest will give you an unsigned int stored at address
0xFFFF1166, assuming that this address is suitable for storing an unsigned
int at all. If it isn't, your program may crash at the first attempt to
use mrtest...
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: