user13674: So I am working with the SoftwareSerial library. I'm looking at the write function and I see a *reg value being manipulate. I want to find the value of *reg so I traced the value by stepping into each function call.so here we go.
*reg = _transmitPortRegister
_transmitPortRegister = portOutputRegister(port) //I'm working with pin 1 in register D

Continuing...
#define portOutputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_output_PGM + (P))) )

const uint16_t PROGMEM port_to_output_PGM[] = {
    NOT_A_PORT,
    NOT_A_PORT,
    (uint16_t) &PORTB,
    (uint16_t) &PORTC,
    (uint16_t) &PORTD,
};

My first question is what is the point of (uint16_t) &PORTD? I am assuming that's just the value of PORTD's register because it is being anded with an empty 16 bit int. 
Continuing on, 
#define PORTB _SFR_IO8(0x05)
#define PORTC _SFR_IO8(0x08)
#define PORTD _SFR_IO8(0x0B)

#define _SFR_IO8(io_addr) _MMIO_BYTE((io_addr) + __SFR_OFFSET)
#define __SFR_OFFSET 0x20

#define _MMIO_BYTE(mem_addr) (*(volatile uint8_t *)(mem_addr))

Now, I followed it all the way here. But how do I find out what actually is the deferenced value? Since this is all IDE, i'm not sure how to GDB this either.
LASTLY, the write function takes in a parameter b, which is a byte. Now in the write function, this is the code to write.
// Write each of the 8 bits
for (uint8_t i = 8; i > 0; --i)
{
  if (b & 1) // choose bit
    *reg |= reg_mask; // send 1
  else
    *reg &= inv_mask; // send 0

  tunedDelay(delay);
  b >>= 1;
}

In that block of code, I am not quite sure why they are doing b & 1. Are they just anding the whole byte with 1? If so, then why comment it as "choose byte" 
and inside the if-else blocks, they're just oring *reg with reg_mask. How does that translate to sending a one? 
Sorry for any confusion, i am glad to clarify any confusing parts of this question. Please let me know. 

user10794: // Write each of the 8 bits
for (uint8_t i = 8; i > 0; --i)
{
  if (b & 1) // choose bit
    *reg |= reg_mask; // send 1
  else
    *reg &= inv_mask; // send 0

  tunedDelay(delay);
  b >>= 1;
}


In that block of code, I am not quite sure why they are doing b & 1. Are they just anding the whole byte with 1? If so, then why comment it as "choose byte" and inside the if-else blocks,

The comment is: choose bit
First, variable b is the byte that is being set. Now, since async serial sends the least-significant bit first, at the start of the loop of 8 iterations, it takes the low-order bit to see if it is set or not:
  if (b & 1) // choose bit

If set, it sets the output port to HIGH (by ORing in the appropriate mask to the appropriate register), otherwise it sets the port to LOW (by ANDing in the appropriate inverted mask to the appropriate register). The inverted mask would be set to every bit but one.
Now look at this:
  b >>= 1;

That shifts the bits right one, throwing away the low-order bit. Now what was previously the second lowest-order bit is now the low-order bit. Then the loop repeats. Now the next bit is sent. And so on for 8 bits.
Imagine we were sending 0x39 (0b00111001). For the 8 iterations of the loop we would see:
00111001  --> 1 sent, then "b" shifted right one
00011100  --> 0 sent, then "b" shifted right one
00001110  --> 0 sent, then "b" shifted right one
00000111  --> 1 sent, then "b" shifted right one
00000011  --> 1 sent, then "b" shifted right one
00000001  --> 1 sent, then "b" shifted right one
00000000  --> 0 sent, then "b" shifted right one
00000000  --> 0 sent, then "b" shifted right one

You can see that the right-most bit is sent (the low-order bit) and then b is shifted right (introducing zeroes at the left), until all 8 bits are sent.

user4143: 
My first question is what is the point of (uint16_t) &PORTD? I am assuming that's just the value of PORTD's register because it is being anded with an empty 16 bit int. 

No.  You're mistaking the operator.  In this context & means the address of, so it is getting the address of the variable called PORTD and casting it to an unsigned 16-bit integer, which it's then storing in the array.

Now, I followed it all the way here. But how do I find out what actually is the deferenced value? Since this is all IDE, i'm not sure how to GDB this either. 

Again, we're talking addresses.  The port register number is (for port D) 0x0B.  Add that to 0x20 and you get 0x2B which is the address of the register in memory.  Then comes the tricky bit:
#define _MMIO_BYTE(mem_addr) (*(volatile uint8_t *)(mem_addr))

Expand that out with 0x2B and you get:
(*(volatile uint8_t *)(0x2B))

Now, working from the inside out we have:
(volatile uint8_t *)(0x2B)

That says this is a pointer to address 0x2B.
Then that is de-referenced to get the value from that pointer with a * operator:
*(volatile uint8_t *)(0x2B)

So you end up with "The value that is in the address 0x2B"
If we then feed that back into the first part of your question, so:
PORTD = (*(volatile uint8_t *)(0x2B))

then &PORTD would be:
&(*(volatile uint8_t *)(0x2B))

The initial & and * cancel each other out (you can think of them as opposites - one is get the address from a value, the other get a value from an address), so you effectively end up with:
(volatile uint8_t *)0x2B


13674: <p>So I am working with the SoftwareSerial library. I'm looking at the write function and I see a *reg value being manipulate. I want to find the value of *reg so I traced the value by stepping into each function call.so here we go.</p>

<pre><code>*reg = _transmitPortRegister
_transmitPortRegister = portOutputRegister(port) //I'm working with pin 1 in register D
</code></pre>

<p>Continuing...</p>

<pre><code>#define portOutputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_output_PGM + (P))) )

const uint16_t PROGMEM port_to_output_PGM[] = {
    NOT_A_PORT,
    NOT_A_PORT,
    (uint16_t) &amp;PORTB,
    (uint16_t) &amp;PORTC,
    (uint16_t) &amp;PORTD,
};
</code></pre>

<p>My first question is what is the point of (uint16_t) &amp;PORTD? I am assuming that's just the value of PORTD's register because it is being anded with an empty 16 bit int. </p>

<p>Continuing on, </p>

<pre><code>#define PORTB _SFR_IO8(0x05)
#define PORTC _SFR_IO8(0x08)
#define PORTD _SFR_IO8(0x0B)

#define _SFR_IO8(io_addr) _MMIO_BYTE((io_addr) + __SFR_OFFSET)
#define __SFR_OFFSET 0x20

#define _MMIO_BYTE(mem_addr) (*(volatile uint8_t *)(mem_addr))
</code></pre>

<p>Now, I followed it all the way here. But how do I find out what actually is the deferenced value? Since this is all IDE, i'm not sure how to GDB this either.</p>

<p>LASTLY, the write function takes in a parameter b, which is a byte. Now in the write function, this is the code to write.</p>

<pre><code>// Write each of the 8 bits
for (uint8_t i = 8; i &gt; 0; --i)
{
  if (b &amp; 1) // choose bit
    *reg |= reg_mask; // send 1
  else
    *reg &amp;= inv_mask; // send 0

  tunedDelay(delay);
  b &gt;&gt;= 1;
}
</code></pre>

<p>In that block of code, I am not quite sure why they are doing b &amp; 1. Are they just anding the whole byte with 1? If so, then why comment it as "choose byte" 
and inside the if-else blocks, they're just oring *reg with reg_mask. How does that translate to sending a one? </p>

<p>Sorry for any confusion, i am glad to clarify any confusing parts of this question. Please let me know. </p>
 10794: <pre><code>// Write each of the 8 bits
for (uint8_t i = 8; i &gt; 0; --i)
{
  if (b &amp; 1) // choose bit
    *reg |= reg_mask; // send 1
  else
    *reg &amp;= inv_mask; // send 0

  tunedDelay(delay);
  b &gt;&gt;= 1;
}
</code></pre>

<blockquote>
  <p>In that block of code, I am not quite sure why they are doing b &amp; 1. Are they just anding the whole byte with 1? If so, then why comment it as "choose byte" and inside the if-else blocks,</p>
</blockquote>

<p>The comment is: choose <strong>bit</strong></p>

<p>First, variable <code>b</code> is the <strong>byte</strong> that is being set. Now, since async serial sends the least-significant bit first, at the start of the loop of 8 iterations, it takes the low-order bit to see if it is set or not:</p>

<pre><code>  if (b &amp; 1) // choose bit
</code></pre>

<p>If set, it sets the output port to HIGH (by ORing in the appropriate mask to the appropriate register), otherwise it sets the port to LOW (by ANDing in the appropriate inverted mask to the appropriate register). The inverted mask would be set to every bit <strong>but</strong> one.</p>

<p>Now look at this:</p>

<pre><code>  b &gt;&gt;= 1;
</code></pre>

<p>That shifts the bits right one, throwing away the low-order bit. Now what was previously the second lowest-order bit is now the low-order bit. Then the loop repeats. Now the next bit is sent. And so on for 8 bits.</p>

<p>Imagine we were sending 0x39 (0b00111001). For the 8 iterations of the loop we would see:</p>

<pre><code>00111001  --&gt; 1 sent, then "b" shifted right one
00011100  --&gt; 0 sent, then "b" shifted right one
00001110  --&gt; 0 sent, then "b" shifted right one
00000111  --&gt; 1 sent, then "b" shifted right one
00000011  --&gt; 1 sent, then "b" shifted right one
00000001  --&gt; 1 sent, then "b" shifted right one
00000000  --&gt; 0 sent, then "b" shifted right one
00000000  --&gt; 0 sent, then "b" shifted right one
</code></pre>

<p>You can see that the right-most bit is sent (the low-order bit) and then <code>b</code> is shifted right (introducing zeroes at the left), until all 8 bits are sent.</p>
 4143: <blockquote>
  <p>My first question is what is the point of (uint16_t) &amp;PORTD? I am assuming that's just the value of PORTD's register because it is being anded with an empty 16 bit int. </p>
</blockquote>

<p>No.  You're mistaking the operator.  In this context <code>&amp;</code> means <em>the address of</em>, so it is getting the address of the variable called <code>PORTD</code> and casting it to an unsigned 16-bit integer, which it's then storing in the array.</p>

<blockquote>
  <p>Now, I followed it all the way here. But how do I find out what actually is the deferenced value? Since this is all IDE, i'm not sure how to GDB this either. </p>
</blockquote>

<p>Again, we're talking addresses.  The port register number is (for port D) 0x0B.  Add that to 0x20 and you get 0x2B which is the address of the register in memory.  Then comes the tricky bit:</p>

<pre><code>#define _MMIO_BYTE(mem_addr) (*(volatile uint8_t *)(mem_addr))
</code></pre>

<p>Expand that out with 0x2B and you get:</p>

<pre><code>(*(volatile uint8_t *)(0x2B))
</code></pre>

<p>Now, working from the inside out we have:</p>

<pre><code>(volatile uint8_t *)(0x2B)
</code></pre>

<p>That says <em>this is a pointer to address 0x2B</em>.</p>

<p>Then that is de-referenced to get the value from that pointer with a <code>*</code> operator:</p>

<pre><code>*(volatile uint8_t *)(0x2B)
</code></pre>

<p>So you end up with "The value that is in the address 0x2B"</p>

<p>If we then feed that back into the first part of your question, so:</p>

<pre><code>PORTD = (*(volatile uint8_t *)(0x2B))
</code></pre>

<p>then <code>&amp;PORTD</code> would be:</p>

<pre><code>&amp;(*(volatile uint8_t *)(0x2B))
</code></pre>

<p>The initial &amp; and * cancel each other out (you can think of them as opposites - one is get the address from a value, the other get a value from an address), so you effectively end up with:</p>

<pre><code>(volatile uint8_t *)0x2B
</code></pre>
