Tech Junk for non-Techies

Geek humor is quite funny to geeks and baffling to everyone else.  Case in point:

Pointers

Pointers

For those who don’t get the joke there, here’s the scoop.

Pointers

Okay, the dude playing the game is asking for help.  He asked for some “pointers,” which, to a non-geek, would be “pointing him in the right direction” of some game help.  To a programmer / hardware design geek, pointers are something altogether different.

A pointer is, simply, an integer variable that holds the memory address of another variable.  Or at least that’s the software end of it.  Even lower level, a pointer is any memory address that’s stored in memory or a CPU register.  In fact, the x86 family of processors has Stack Pointer, Stack Base Pointer, and Instruction Pointer registers that are designed to contain the addresses of the top of the stack (SP/ESP/RSP), bottom of the stack frame (this is the memory address that will contain the return value of the currently-running subroutine) (BP/EBP/RBP), and next CPU instruction to be executed (IP/EIP/RIP), respectively.

So, okay.  Pointers are integers that “point” at addresses in memory.  That’s why they look funny.  Most microcomputer CPUs store integers using a base-2 number system.  That means that there are two possible digits, 0 and 1.  On a processor that can store up to 32 individual binary digits (bits) per integer, writing out the full number in binary would be a bit inconvenient.  As an example, the number 1138 (decimal) would be 00000000000000000000010001110010.  To save time, we could just write it in base-10 as we normally would.  But base-10 doesn’t lend itself to doing math in powers of two which is often very helpful when working with low-level programming and hardware-level engineering.  CPUs are much more efficient when they can move data structures around whose members are aligned to some power of two rather than an arbitrary boundary.  To help us see these powers of two without having to deal with 32 digits at a time, we employ a number base that it itself a power of two:  16.  Originally, software was written in octal, base 8, because processors only handled 8 bits at a time.  Nowadays, processors that handle 64 bits are not uncommon.  So hexadecimal, or base-16, is a convenient way of representing numbers based on a power of 2.  That’s why memory addresses (pointers) are traditionally written in hexadecimal.

So now the joke makes more sense:  The gamer asked for “pointers” and the programmer geek gave him integers representing memory addresses in hexadecimal because that’s what “pointers” are to programmers.

Trivia:  The pointers above are 32-bit addresses.  If they’re for a 32-bit RISC system (say a very old SPARCv1 processor or even an old MIPS chip), they may very well be direct physical RAM addresses since both of these systems had hardware MMUs that could handle them.  If they’re for a 32-bit x86 system (as most PCs were between 1994 and 2006), then they’re virtual memory addresses since, because of backwards-compatibility requirements, all 32-bit x86 processors use segmented memory addressing and physical RAM addresses are given in base:offset format rather than 32-bit integers.

Exercise:  Figure out what the above hexadecimal integers would be in Decimal.  Extra cookies:  figure out what they would be in Binary!

Advertisements

, , ,

  1. #1 by Chadwick on June 11, 2010 - 9:23 AM

    Um…no.

    • #2 by Joshua on June 11, 2010 - 9:27 AM

      No to which? Or the entire post?

      • #3 by Chadwick on June 11, 2010 - 9:56 AM

        I reject your exercise and substitute my own.

  2. #4 by Chadwick on June 11, 2010 - 11:36 AM

    Huh. This was post #1000.

    • #5 by Joshua on June 11, 2010 - 11:39 AM

      Hooray! I get a cookie now!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: