CSSE 132 Mini-reading

Memory Addresses in 10 Minutes

Review byte-addressable memory, address-space calculations, and big-endian versus little-endian byte order.

Why This Matters

In CSSE 132, you will read memory diagrams, work with pointers, and trace values that occupy several bytes. To do that correctly, you need to know how addresses select bytes, how many bytes an address space can contain, and how a computer orders the bytes of a larger value.

Core Idea

From a software perspective, main memory is a large array. Each entry holds exactly one byte, and each entry has a numeric index called an address. Addresses are usually written in hexadecimal because hex is a compact way to write binary.

One address selects one byte

If a byte appears at address 0x102, that address identifies one 8-bit memory entry. A four-byte value occupies four consecutive addresses.

Address bits determine capacity

An n-bit address has 2n possible patterns. In the byte-addressable model used in this lecture, that means an address space of 2n bytes.

For example, a 2-bit address can be 00, 01, 10, or 11. Those four addresses select four bytes. The address values run from 0 through 3, but there are four entries because counting starts at 0.

If a system must address N bytes, choose the smallest number of bits whose address space is large enough:

address bits = ⌈log2(N)⌉

The lecture also uses binary large quantities: 1 K = 210, 1 M = 220, and 1 G = 230. When the unit is bytes, write KB, MB, or GB.

Worked Examples

Example 1: Convert a large byte quantity

Convert 226 B to megabytes. One megabyte is 220 B, so separate out that factor:

226 B
= 26 × 220 B
= 64 MB

This makes sense because the difference between the exponents is 6, and 26 = 64.

Example 2: Find the required address width

A memory contains 20 bytes. Four address bits are too few because 24 = 16. Five bits work because 25 = 32.

⌈log2(20)⌉ = 5 address bits

The 5-bit address space has room for 32 byte addresses. It can address all 20 required bytes even though some possible addresses remain unused.

Example 3: Find the address-space capacity

In the model used by the lecture and Worksheet 03, a 32-bit CPU supports 32-bit addresses. Therefore it can form 232 different addresses:

232 B
= 22 × 230 B
= 4 GB

Notice that the result is in bytes, not bits. Each address selects one byte.

Example 4: Store a multi-byte value

Split 0x0A0B0C0D into bytes first. Every two hex digits form one byte: 0x0A, 0x0B, 0x0C, and 0x0D. Suppose the value starts at address 0x400.

Byte order0x4000x4010x4020x403
Big-endian0x0A0x0B0x0C0x0D
Little-endian0x0D0x0C0x0B0x0A

Big-endian places the most significant byte at the lowest address. Little-endian places the least significant byte at the lowest address. The bits inside each byte keep their order.

Example 5: Read bytes from memory

A four-byte integer begins at 0x010. Memory contains 0xFF at 0x010, followed by three 0x00 bytes at increasing addresses.

On a big-endian system, the first byte is most significant, so the value is 0xFF000000. On a little-endian system, the first byte is least significant, so the value is 0x000000FF.

Common Mistakes

Confusing the number of addresses with the largest address

Three bits give eight addresses, numbered 0 through 7. The largest address is 7, but the address space contains 8 bytes.

Mixing up bits and bytes

An n-bit address does not mean each memory entry contains n bits. In this course model, each address selects one 8-bit byte.

Rounding the logarithm down

Four bits address only 16 bytes, so 20 bytes require 5 bits. Round up unless N is already an exact power of 2.

Reversing hex digits instead of bytes

Endianness rearranges whole bytes. Split a hex value into two-digit groups before placing it in memory.

Quick Reference

QuestionRule
How many bytes can n address bits select?2n B
How many bits address N bytes?⌈log2(N)⌉
What addresses exist?0 through 2n - 1
What is one byte?8 bits, represented by two hex digits
What does big-endian store first?The most significant byte at the lowest address
What does little-endian store first?The least significant byte at the lowest address

Large quantities: K = 210, M = 220, and G = 230.

Check Yourself

Try these before opening the answers. The values differ from the worksheet.

  1. Convert 227 B to megabytes.
  2. What is the minimum address width needed for 70 bytes?
  3. How many bytes can a 12-bit address space contain? Express the result using an appropriate large quantity.
  4. Store 0x12345678 beginning at 0x200 on a little-endian system. What byte appears at each of addresses 0x200 through 0x203?
  5. At increasing addresses 0x300 through 0x303, memory contains DE AD BE EF. What four-byte value does this represent on a big-endian system? What value does it represent on a little-endian system?

Answers

Show the answers
  1. 128 MB, because 227 B = 27 × 220 B.
  2. 7 bits. Six bits provide only 64 addresses, while 7 bits provide 128.
  3. 212 B = 4 × 210 B = 4 KB.
  4. 0x200: 0x78, 0x201: 0x56, 0x202: 0x34, and 0x203: 0x12. The least significant byte goes at the lowest address.
  5. Big-endian: 0xDEADBEEF. Little-endian: 0xEFBEADDE.

Next Step

Complete Worksheet 03 and draw the address of every byte in each endianness problem. Labeling addresses before placing bytes makes the order much easier to check.