Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Bitwise questions with the following code

Reply
Thread Tools

Bitwise questions with the following code

 
 
Krumble Bunk
Guest
Posts: n/a
 
      01-27-2006
Good morning c.l.c,

I have a question regarding the following snippet of code.

static inline void WriteMemory(register word Address,register byte
Value)
{
MemoryPage[Address>>13][Address&0x1FFF]=Value;
}


1) Why is 'Address' shifted right by 13 places? What is that actually
doing? (apart from dividing). What i'm getting at, is why use those
precise values? 13 and 0x1FFF - what's special about them, indivudually
and in combination in the 2D array?

I realise there's not an awful lot of information to go on, but any
help is very much appreciated.

Thanks

KB

 
Reply With Quote
 
 
 
 
Walter Roberson
Guest
Posts: n/a
 
      01-27-2006
In article <. com>,
Krumble Bunk <> wrote:

>I have a question regarding the following snippet of code.


>static inline void WriteMemory(register word Address,register byte
>Value)
>{
> MemoryPage[Address>>13][Address&0x1FFF]=Value;
>}



>1) Why is 'Address' shifted right by 13 places?


Why not?

>What is that actually
>doing? (apart from dividing).


Bit sub-selection.

> What i'm getting at, is why use those
>precise values? 13 and 0x1FFF - what's special about them, indivudually
>and in combination in the 2D array?


0x1FFF is the mask that selects exactly 13 trailing bits.
(2<<N)-1 is a binary mask used to select N trailing bits.

Why 13 instead of (say) 12 or 14? Insufficient information.
Presumably the above is either implimenting or mimicing a real
hardware situation.
--
Is there any thing whereof it may be said, See, this is new? It hath
been already of old time, which was before us. -- Ecclesiastes
 
Reply With Quote
 
 
 
 
CBFalconer
Guest
Posts: n/a
 
      01-27-2006
Krumble Bunk wrote:
>
> I have a question regarding the following snippet of code.
>
> static inline void WriteMemory(register word Address,register byte
> Value)
> {
> MemoryPage[Address>>13][Address&0x1FFF]=Value;
> }
>
> 1) Why is 'Address' shifted right by 13 places? What is that
> actually doing? (apart from dividing). What i'm getting at, is
> why use those precise values? 13 and 0x1FFF - what's special
> about them, indivudually and in combination in the 2D array?


Apart from the fact that the types word and byte have not been
defined, you might think about the number of bits preserved by the
mask 0x1fff. Then consider the physical organization of your
system (which is OT here).

In general you would be better advised to include spaces in your
expressions for clarity. The blank shortage ended a few years ago.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>


 
Reply With Quote
 
Nudge
Guest
Posts: n/a
 
      01-27-2006
Krumble Bunk wrote:
> I have a question regarding the following snippet of code.
>
> static inline void WriteMemory(register word Address,
> register byte Value)
> {
> MemoryPage[Address>>13][Address&0x1FFF] = Value;
> }


(comp.arch seems more appropriate to discuss this topic.)

I'd start with:

http://en.wikipedia.org/wiki/Page_table
http://en.wikipedia.org/wiki/Paging
http://en.wikipedia.org/wiki/Virtual_memory
 
Reply With Quote
 
Krumble Bunk
Guest
Posts: n/a
 
      01-27-2006

Nudge wrote:
> Krumble Bunk wrote:
> > I have a question regarding the following snippet of code.
> >
> > static inline void WriteMemory(register word Address,
> > register byte Value)
> > {
> > MemoryPage[Address>>13][Address&0x1FFF] = Value;
> > }

>
> (comp.arch seems more appropriate to discuss this topic.)
>
> I'd start with:
>
> http://en.wikipedia.org/wiki/Page_table
> http://en.wikipedia.org/wiki/Paging
> http://en.wikipedia.org/wiki/Virtual_memory


thanks for all your help

kb

 
Reply With Quote
 
Krumble Bunk
Guest
Posts: n/a
 
      01-27-2006

Nudge wrote:
> Krumble Bunk wrote:
> > I have a question regarding the following snippet of code.
> >
> > static inline void WriteMemory(register word Address,
> > register byte Value)
> > {
> > MemoryPage[Address>>13][Address&0x1FFF] = Value;
> > }

>
> (comp.arch seems more appropriate to discuss this topic.)
>
> I'd start with:
>
> http://en.wikipedia.org/wiki/Page_table
> http://en.wikipedia.org/wiki/Paging
> http://en.wikipedia.org/wiki/Virtual_memory


thanks for all your help

kb

 
Reply With Quote
 
Arndt Jonasson
Guest
Posts: n/a
 
      01-27-2006

"Krumble Bunk" <> writes:
> Good morning c.l.c,
>
> I have a question regarding the following snippet of code.
>
> static inline void WriteMemory(register word Address,register byte
> Value)
> {
> MemoryPage[Address>>13][Address&0x1FFF]=Value;
> }
>
>
> 1) Why is 'Address' shifted right by 13 places? What is that actually
> doing? (apart from dividing). What i'm getting at, is why use those
> precise values? 13 and 0x1FFF - what's special about them, indivudually
> and in combination in the 2D array?


If the programmer had followed the practice of giving names to the
"magic numbers" in the code, it would have been easier for you to
obtain the answers to those questions. See for example:

http://en.wikipedia.org/wiki/Magic_n...umbers_in_code
 
Reply With Quote
 
Martin Ambuhl
Guest
Posts: n/a
 
      01-27-2006
Krumble Bunk wrote:
> Good morning c.l.c,
>
> I have a question regarding the following snippet of code.
>
> static inline void WriteMemory(register word Address,register byte
> Value)
> {
> MemoryPage[Address>>13][Address&0x1FFF]=Value;
> }
>
>
> 1) Why is 'Address' shifted right by 13 places? What is that actually
> doing? (apart from dividing). What i'm getting at, is why use those
> precise values? 13 and 0x1FFF - what's special about them, indivudually
> and in combination in the 2D array?
>
> I realise there's not an awful lot of information to go on, but any
> help is very much appreciated.


This is really not a C question, but about a particular platform's
addressing scheme. That makes CLC the wrong place for the question.
However, it appears that the memory mapping is done by page+offset; If
'Address' is 16 bits (the type 'word' is not a C type), then the page is
in bits 13-15 and the offset in bits 0-12. Address & 01FF yields the
offset; Address >> 13 yields the page.



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
The Web server reported the following error when attempting to create or open the Web project located at the following URL: 'http://localhost/822319ev1'. 'HTTP/1.1 500 Internal Server Error'. chanmm ASP .Net 2 09-07-2010 07:37 AM
Two questions about the following lines of code Chad C Programming 7 08-26-2007 04:46 PM
how to convert the following ASP code to perl code DavidNorep Perl Misc 0 05-06-2007 12:35 PM
RE: The Web server reported the following error when attempting to create or open the Web project located at the following URL: <URL> =?Utf-8?B?VHJldm9yIEJlbmVkaWN0IFI=?= ASP .Net 0 06-07-2004 07:36 AM
Two Questions about the Following Block of Code Greener Javascript 3 10-09-2003 05:29 PM



Advertisments