There are 2 kinds of addresses: program address and memory address

  1. Program address:

    • A program address identifies the location of (1) a computer (program) instruction or (2) a variable in the program

    • Addresses (and labels) used in computer programs are program addressss

  2. Memory address:

    • A memory address identifies the location of memory cells (bytes)

    • Addresses transmitted on the address bus are memory addressss



    Believe if or not:

    • Program addresses and memory addresses are not the same !!!

Program addresses: addresses used in computer programs

  • The program address identifies a location in a computer program:

    • Each instruction/variable in a program is identified by a program address

  • Examples of program addresses:

Program addresses: addresses used in program execution

  • The CPU executes instructions in a program:

    • Therefore:   addresses used by the CPU are (always)   program addresses

Memory addresses: addresses used to select memory cells

  • A memory address identifies a location in the memory:

    • Each byte in the computer memory is identified by a memory address

  • Examples of memory address:

Memory addresses: addresses used in memory selection

  • A memory cell selected by an address on the address bus:

    • Addresses transmitted on the address bus are (always)   memory addresses

What you have learned so far

  • For simplicity sake, until now in your Computer Science eduction, we have used:

       Memory address = Program address
    

You will now learn the reality

  • In reality, there is a device (called the Memory Management Unit) that maps:

       Memory address = f( Program address )
    

Background info: machine codes, labels and binary numbers

  • A computer stores everything as binary numbers

  • So:   program addresses are stored as binary numbers:

      assembler program      Assembler  Machine code
     =======================   ---->    ===================================
      movw  r0, #:lower16:x             11100011 00001000 00000111 10010100
      movt  r0, #:upper16:x             11100011 01000000 00000000 00000001
      ldr  r0, [r0]                     11100101 10010000 00000000 00000000
    
       .data
    x: .4byte  7777     // address x = 00000000 00000001 10000111 10010100
                                     = 34708 (decimal)
    

  • Notice that:

    • A label (e.g.: x) denotes/marks a location within a computer program

      • Labels are translated into a binary address by the assembler

DEMO: demo/VirtualMemory/machine-code.s

Execution of a computer program by the CPU

  • Computer programs are stored on disks:

     

     

Execution of a computer program by the CPU

  • A program must be placed/stored in memory in order to run :

  • Because:

    • The CPU can only fetch instructions from the memory

The "straightforward" placement of a computer program in the computer memory

  • The straightforward way to place a program in memory is starting at location 0:

  • Using the straightforward placement, we have that:

       memory address = program address
    

Advantage of the "straightforward" placement

  • Advantage of the straightforward placement:

    • Easy to understand (so we can focus on Computer Science topics) because the program can be executed without an MMU:

Disadvantage of the "straightforward" placement

  • You cannot place multiple programs in the same memory location:

  • In order to execute multiple programs at the same time:

    • Programs must be placed in memory (starting) at different locations

The effect of placing program at a different memory location

  • Consider the same computer program placed in memory starting at memory location 51200:

  • We cannot use the program address 0 to fetch the first instruction in the program from memory because:

     The first instruction of the program is stored at memory address 51200
    

The effect of placing program at a different memory location

  • Consider the same computer program placed in memory starting at memory location 51200:

  • We cannot use the program address 34708 to access the variable x in the program from memory because:

     The variable x in the program is stored at memory address 85908
    

Another requirement for program execution

  • The entire program must be stored in memory in order to run the program:

  • Consequence of this requirement:

    • Program size was limited by the memory size !!!

Intro to Virtual Memory

  • Before the invention of Virtual Memory, the size of the main memory will limit the size of programs that can be run:

    • This constraint was very critical back around 1960 because computers only have a few K bytes of memory

Intro to Virtual Memory

  • The virtual memory technique stores the running program on the (larger but slower) disk (memory):

    • Program stored on disk cannot be run by the CPU
      ( Key:   you don't need the whole program stored in memory to run it !!)

Intro to Virtual Memory

  • The virtual memory technique will store only the portions of a program that is needed in main memory:

    • The CPU executes the current instruction
      So execution only needs the current instr and its (memory) operands

Virtual Memory vs. Cache

  • The Virtual Memory technique is similar to cache:

    Caching Virtual Memory
    • The cache pretends to be the memory

    • The main memory contains all the data

    • The cache stores a portion of data stored in main memory
       

    • The cache is able to increase the speed of the memory access operations
    • The disk pretends to be the memory

    • The disk contains the complete running program

    • The main memory stores a portion of running program stored on disk

    • The disk is able to increase the size of the main memory capacity
       

  • Using the Virtual Memory technique, yours truly was able to:

    • Run my programs on a PDP 11 that has 8 K bytes of memory when I was an undergrad