Presentation is loading. Please wait.

Presentation is loading. Please wait.

Mastering Memory Modes

Similar presentations


Presentation on theme: "Mastering Memory Modes"— Presentation transcript:

1 Mastering Memory Modes
*the types of Addressing Memory modes and low level languages Ways to locate data and instructions in memory MEMORY ADDRESS MODES 5 modes: Direct, indirect, immediate, indexed and relative

2 The main question we need to ask ourselves before we start is:
? What are the ways in which DATA and INSTRUCTIONS can be LOCATED IN MEMORY? There are many ways in which this can be done, and these methods are called: MEMORY ADDRESS MODES

3 What are Memory Addressing Modes?
Memory address modes determine the method that is used inside a program to ACCESS DATA (from within the CPU or the external RAM) Some memory modes can actually control program flow. This is the CPU board of someone’s first computer: a Southwest Technical Products A 8/16 bit microprocessor: relatively orthogonal instruction set, advanced addressing modes, hardware multiply, and 16 bit arithmetic …. .

4 Why do we need to know about them?
In Computer Programing, addressing modes are primarily of interest to COMPILER writers and to those who write code directly in assembly *It is useful to note that high level languages also make use of memory address modes but the COMPILER is responsible from hiding the details of what is happening from the programmer. *if you are using a low level language, direct use of these modes would be made, and that’s the difference. *One of the questions a low level programmer will ask is, which memory mode address is right for me. Every memory mode has it’s pros and cons and the programmer needs to evaluate which method would work best in his/her code.

5 Types of Addressing Immediate Addressing Direct Addressing
CAN YOU ORDER THESE IN ORDER OF HOW FAST THE METHOD OF ADDRESSING IS? Immediate Addressing Direct Addressing Indirect Addressing Indexed Addressing Relative Addressing

6 Types of Addressing Immediate Addressing Direct Addressing
CAN YOU ORDER THESE IN ORDER OF HOW FAST THE METHOD OF ADDRESSING IS? Immediate Addressing Direct Addressing Indirect Addressing Indexed Addressing Relative Addressing

7 Immediate Addressing Direct Addressing
Types of Addressing CAN YOU ORDER THESE IN ORDER OF HOW FAST THE METHOD OF ADDRESSING IS? Immediate Addressing Direct Addressing Indirect Addressing Indexed Addressing Relative Addressing

8 Immediate Addressing Immediate addressing means that the data to be used is HARD- CODED into the instruction itself. This is considered among the FASTEST methods of addressing and that is because it is does not involve MAIN MEMORY at all. Example: Suppose you wanted to add 3 to the content of the accumulator: = ADC 3

9 Direct Addressing This is also called "Absolute addressing"
It is a very simple and efficient way of addressing memory (not quite as fast as Immediate addressing) In Direct Addressing the code given refers directly to a location in memory. The value held in the absolute location “107” in RAM is subtracted from the accumulator A disadvantage here is that the code depends on the correct data always being present at the same location

10 Direct Addressing contd.
The disadvantage of Direct Addressing is not trivial! Generally speaking, it is a good idea to avoid referring to absolute memory addresses in order to have “re-locatable code” i.e. code that does not depend on specific locations in memory

11 So when is Direct Addressing used?
Good question ! Well, we’ve already discussed the fact that it is FAST (not as fast however, as immediate addressing) You could also use Direct Addressing on computers that are only running a ….. Single program! This sort of computer would probably only ever run the code that the programmers have hard wired (or programmed) into it. Therefore, DIRECT MEMORY ADDRESSING IS GREAT FOR  FAST MEMORY ACCESS But not as fast as … Immediate Addressing!

12 Match the addressing mode to the definition
????????????????????????????????????? ?????????????????????????????????????

13 Before we move on let’s try some past paper questions and answers
Machine Orientated 2.Related to the design of the computer 3. Includes assembly language /machine code 4. May use mnemonics for operations Questions taken from OCR past paper F453 June 2012 5. May use labels for addresses

14 Opcode: Mnemonic part of the instruction
2. The opcode indicates what it is TO DO 3. In the above example: e.g. “add” 4. Operand: address field in the instruction 5. Holds data or the address to be used e.g. 45

15 Data in the operand is the value to be used by operator
2. e.g. “ADD 45” adds the value 45 directly 3. In this case 45 would be added to the accumulator

16 Uses data in the operand as the ‘address’ of data
2. e.g. “ADD’ 45 is referring to the address 45 not data 3. The value that is held in the address 45 is added to the 4. …accumulator

17 Indirect Addressing This is when the address of the data is actually held in an INTERMEDIATE location. This means that the address is first “looked up” and then used to find the data itself. So how does the programmer access the subroutines within the library if he does not know the starting address of each routine? Consider the following scenario: A number of programs use libraries of software that may get loaded into memory at run time by the loader. Now, this is the important bit: The loader will most likely place the library in a different memory location each time.

18 The answer is indirect addressing!
RAM Location 5002 Vector Table 9000 RAM Location 9000 RAM Location 3001 7 5002 Note: A vector processor, or array processor, is a central processing unit (CPU) that implements an instruction set containing instructions that operate on one-dimensional arrays of data called vectors. This is in contrast to a scalar processor, whose instructions operate on single data items. 1. Location 3001 holds the address of an item within a vector table (location 5002) 2. This location (5002) in the vector table contains the address of the data to be fetched 3. The data is fetched from location 9000 (as directed by the Vector table or second location)

19 MOV A, @5002 5002 9000 7 RAM Location 5002 RAM Location 3001
Vector Table RAM Location 3001 RAM Location 9000 5002 9000 7 A specific block of memory would be used by the loader to store the starting address of Every subroutine in the library. 3. A typical assembly language instruction would look like MOV Note: A vector processor, or array processor, is a central processing unit (CPU) that implements an instruction set containing instructions that operate on one-dimensional arrays of data called vectors. This is in contrast to a scalar processor, whose instructions operate on single data items. A vector table just holds addresses rather than data. 2. This block of memory is called a vector Table. A vector table just holds addresses rather than data. 4. The above instruction is basically … Looking to location 5002 for an address The address 5002 is used to fetch data which is stored at another address and load it into the accumulator. c) In this instance the data being fetched is 7 ? ? ? ? ?

20 OFFSET and BASE ADDRESS Indexed Addressing
When you think of Indexed Addressing you need to immediately remember these two words OFFSET and BASE ADDRESS It is also pretty fast (as we’ll see in the next few slides) Array in memory Index adds an Offset to the Base address Nth element Base address 1012 First element Final address = base address + index

21 So what is indexed addressing?
Indexed addressing is when you add an OFSET to a BASE ADDRESS to determine the FINAL ADDRESS As it happens, a chunk of data is often stored as a complete or contiguous block in memory. At this point, it is useful to think about an array. It is useful to store an array as contiguous blocks in memory (one after the other without a gap)

22 So what is indexed addressing?
An array always has a/an: BASE ADDRESS In an array the base address refers to the location of the first element. INDEX An index is then used to add an offset to the base address in order to fetch another element in the array. 5 6 7 Null Memory Location

23 More on Indexed Addressing
It allows a real address to be calculated From a base address …by adding the relative address The relative address works as an OFFSET It can be used for Arrays Can also be used for branching From OCR Computing F453 Past Paper

24 A few questions and answers …
IMMEDIATE Definitions taken from: (F453 Revision Notes .pdf Document) DIRECT

25 Relative Addressing Sometimes a program only needs to jump a little bit (or a specified amount) to get to the next instruction. It could be that the next instruction is always only a certain number of locations away from the current instruction. One way of dealing with this is to add just a small offset to the current address in the program counter. (The program counter always points to the next instruction to be executed). This is called “relative addressing”


Download ppt "Mastering Memory Modes"

Similar presentations


Ads by Google