Presentation is loading. Please wait.

Presentation is loading. Please wait.

Module 10 Adapted By and Prepared James Tan © 2001.

Similar presentations


Presentation on theme: "Module 10 Adapted By and Prepared James Tan © 2001."— Presentation transcript:

1 Module 10 Adapted By and Prepared James Tan © 2001

2 Objectives In this lecture we will be looking at : Addressing Mode Typical fetch & execute cycle in a CPU

3 10.1 Assembly Programming Techniques The specified address should be as short as possible  Less time & space For table of data  Use index method.

4 10.2 Addressing Mode  Direct Addressing  The operand address field contains the address of the operand. Example: LOCN 03:OPCODE1001 0110 (96) (LDA) LOCN 04:OPERAND0000 0000 (00) Two limitations –Need 2 bytes of code –Not efficient for processing data arrays or tables, as it can only access a single fixed address at one time  no good for scanning table of data.

5 Page Addressing Consider ADD 2007 Direct addressing can be improved by using 2 registers: –Instruction Register : storing ADD 7 –Page Register (in thousands) : storing 2 –Effective address = 2007 Acc  Acc + (content of loc 2007)

6 Further development of page addressing Page Zero Addressing –Although at page 4, but page bit = 0  Address = 0038 Current Page Addressing –Although at page 4, but page bit = 1  Address = 4038 AddressInstructionPage Bit 4010ADD 380 AddressInstructionPage Bit 4010ADD 381

7 10.2.2 Indirect Addressing The operand address field gives the address of a memory location which contains the address of the operand. Note: M6800 series does not have indirect Example:ADD @ 100 @ : indirect symbol Meaning: go to location 100, get its contents and use it as an address, go to that address and add its contents to the accumulator.

8 10.2.3 Immediate Addressing The operand address field contains the operand. Example:ADD #4 # : Immediate symbol Meaning: Add the number 4 immediately to Acc. Good programming habit: –Use Constants M = 4 LDA M

9 10.2.4 Indexed Addressing Address of Operand = (Index Register)+(Operand Address Field) Related Instructions LDXLoad the index register INXincrement the index register DEXdecrement the index register STXstore the contents of index\register in memory

10 Example ADDA $15, X ADDA: add to Acc $15: dollar sign  Hex number X: index register contents Meaning: ‘add the contents of location whose address is (15 16 + index register contents) into accumulator A’. Consider LDA 50, X[see page 10.8 for details] Resultant Address is 53

11 10.2.5 Relative Addressing Address of Operand = (PC) + (Operand Address Field). Example: BRANCH instruction: BRA * + 5 Effect: PC = PC + 5 5 : offset Some factors to consider: Negative Branch Distance: 2’s complement PC is incremented to point to next instruction before the calculation of branch distance takes place,

12 Program Example 1: Forward Branching Address 0BRA LOOP 1OFFSET 2  PCROLA 3PSHB 4LOOPADD 5 OFFSET = 2, PC = 2 PC = PC + OFFSET = 2 + 2  4

13 Program Example 2: Backward Branching Address 0LOOPCLR 1ASRA 2 ROLA 3PULA 4NOP 5NEGA 6BRA LOOP 7OFFSET 8  PC OFFSET = negative 8  F8 in two’s complement PC = 8

14 10.2.6 & 7 Register Direct/Indirect Addressing Only used in CPU which supports it

15 Stack Addressing Uses Stack Pointer (SP) Has Push and Pop operations Consider Page 10.10 SP = 100,Acc A = 56 10 Acc B = 31 10 Push A  Location 100 = 56  SP = 99 Push B See End result at page 10.11 Question: How about result of the following instructions? Pop A Pop B

16 10.3Fetch & Execute Cycle See File: CE_10B.ppt

17 End of Lecture


Download ppt "Module 10 Adapted By and Prepared James Tan © 2001."

Similar presentations


Ads by Google