Part A - Introduction


Define the units for building local variables and constants

"BYTE is a deliberate respelling of bite to avoid accidental mutation to BIT"
(Bemer, RW and Buchholz, W. 1962)

Units | Addresses | Exercises

The information stored in RAM includes both program instructions and the data used or produced by those instructions.  This information is stored in bits, bytes and words.  The two most common numbering systems for representing information stored in RAM are the binary and hexadecimal numbering systems. 

This chapter defines these units, reviews the numbering systems and describes the method of addressing RAM. 



The most fundamental unit of modern computers is the binary digit or bit.  A bit is either on or off.  One represents on, while zero represents off. 

Because bits are too numerous to handle individually, we adopt larger units and define those units as groups of bits. 


The fundamental addressable unit of RAM is the byte.  One byte consists of 2 nibbles.  Each nibble consists of 4 bits

Nibble Nibble
Bit Bit Bit Bit Bit Bit Bit Bit

In one byte, we can store any one of 256 (28) possible values: 

 00000000 <- 0
 00000001 <- 1
 00000010 <- 2
 00000011 <- 3
 00000100 <- 4
 00111000 <- 56
 11111111 <- 255 

The binary values are on the left.  The equivalent decimal values are on the right.  Note that our counting system starts from 0, not from 1. 


We call the natural size of the execution environment a word.  A word consists of an integral number of bytes and is typically the size of the CPU's general registers.  Word size may vary from machine to machine.  On a 16-bit machine, a word consists of 2 bytes.  On a Pentium 4 machine, the general registers contain 32 bits and a word consists of 4 bytes.  On an Itanium 2 machine, the general registers contain 64 bits, but a word still consists of 4 bytes. 


The most convenient numbering system for representing information is the hexadecimal system (base 16).  Two hexadecimal digits holds the information stored in one byte.  Each digit holds 4 bits of information.  The digit symbols in the hexadecimal number system are {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F}.  The characters A through F denote the decimal values 10 through 15 respectively.  We use the 0x prefix to identify a number as hexadecimal (rather than decimal - base 10). 

 00000000 -> 0x00
 00000001 -> 0x01
 00000010 -> 0x02
 00000011 -> 0x03
 00000100 -> 0x04
 00111000 -> 0x38
 11111111 -> 0xFF 

For example, the hexadecimal value 0x5C is equivalent to the 8-bit value 010111002

To learn how to convert between hexadecimal and binary refer to the chapter entitled Data Conversions in the Appendices. 


Each byte of RAM has a unique address.  A linear map provides a simple method of addressing any byte in RAM.  Addressing starts at zero, is sequential, and ends at the address equal to the size of RAM less 1. 

For example, 4 Gigabytes of RAM

  • consists of 32 (= 4 * 8) Gigabits
  • has a low address of 0x00000000
  • has a high address of 0xFFFFFFFF
1 Byte
1 Byte
1 Byte
1 Byte
Hex: 1 Nibble1 Nibble 1 Nibble1 Nibble 1 Nibble1 Nibble ... 1 Nibble1 Nibble
Contents:                                                 ...                
Hex: 0x00000000 0x00000001 0x00000002 ... 0xFFFFFFFF

Note that each byte, and not each bit, has its own address.  We say that RAM is byte-addressable.


The abbreviations for groups of bytes are:

  • Kilo or k (=1024): 1 Kilobyte = 1024 bytes ~ 103 bytes
  • Mega or M (=1024k): 1 Megabyte = 1024 * 1024 bytes ~ 106 bytes
  • Giga or G (=1024M): 1 Gigabyte = 1024 * 1024 * 1024 bytes ~ 109 bytes
  • Tera or T (=1024G): 1 Terabyte = 1024 * 1024 * 1024 * 1024 bytes ~ 1012 bytes
  • Peta or P (=1024T): 1 Petabyte = 1024 * 1024 * 1024 * 1024 * 1024 bytes ~ 1015 bytes
  • Exa or E (=1024P): 1 Exabyte = 1024 * 1024 * 1024 * 1024 * 1024 * 1024 bytes ~ 1018 bytes

Note that the multiplying factor is 1024, not 1000.  1024 bytes is 210 bytes, which is approximately 103 bytes. 

Limit on Addressability

The maximum size of addressable RAM depends on the size of the address registers in the CPU.  The highest address that is accessible is the largest address that an address register can hold: 

  • On Pentium machines where the address registers hold 32 bits, the maximum size of addressable memory is 4 GB (Gigabytes) (addresses can range from 0 to 232-1, that is 0 to 4,294,967,295). 
  • On Pentium machines where the address registers hold 36 bits, the maximum size of addressable memory is 64 GB (Gigabytes) (addresses can range from 0 to 236-1, that is 0 to 68,719,476,735). 
  • On Itanium 2 machines the address registers hold 64 bits and the maximum size of addressable memory is 16 EB (Exabytes) (addresses can range from 0 to 264-1, that is 0 to 18,446,744,073,709,551,615). 

Segmented Memory

The segmented memory model is a logical technique for managing the addresses of large numbers of bytes.  This model distinguishes segments of memory by their contents.  With segmented memory, program instructions reside in one dedicated segment, global data in another segment and local program data in yet another segment.

Segment Symbol:
Segment Address: 0x0100 0xD3A0 0xF5B0

Segmentation provides a layer of protection.  If a program instruction attempts to change information in the CS segment or to execute information in the DS or SS segment, the CPU reports a segmentation fault and terminates execution. 

In a segmented memory model, an address consists of two parts.  We express it in segment:offset notation


To obtain the physical address multiply the segment value by 0x10 and add the offset value to the result.  For example, the physical address of 0100:006A is 0x0100 * 0x10 + 0x006A = 0x0106A.


   Printer Friendly Version of this Page print this page     Top  Go Back to the Top of this Page
Previous Reading  Previous: Computers Next: Compilers   Next Reading

  Designed by Chris Szalwinski   Copying From This Site   

Creative Commons License