Microcontroller Fundamentals Programming Addressing Modes 1 Addressing Modes


















- Slides: 18

Microcontroller Fundamentals & Programming Addressing Modes 1

Addressing Modes • Addressing Modes define the different methods, instructions obtain data required for its execution. • What are 68 hc 11 instructions ? • Examples: LDAA LDAB BRA #$55 $20, X $2000 BEGIN Some 68 HC 11 instructions. 2

Types of Addressing Modes § The 68 HC 11 has 6 addressing modes: 1. Direct 2. Extended 3. Index 4. Immediate 5. Inherent 6. Relative 3

Direct Addressing Mode • Access data from memory $00 to $FF. • Instruction makes up of 2 bytes machine code. • (one byte of Op-code , one byte of Operand Address). Example: LDAA $30 ; contents of memory ($0030) ; load into ACCA Op-code Operand Address 4

Example LDAA $30 ; contents of memory ($0030) ; load into ACCA. Before execution CPU ACCA $FF After execution Memory CPU Memory B 6 $002 F 55 $0030 3 C $0031 ACCA $55 5

Extended Addressing Mode § Almost similar to Direct Addressing Mode. § Accessed data from memory ($0100) to ($FFFF). § Instruction consists 3 bytes of machine code. ( one opcode and two operands = 3 bytes ). Example: LDAA Op-code $8830 ; contents of memory ($8830) ; loaded into ACCA Operand (2 -bytes) 6

Example LDAA $8830 ; contents of memory ($8830) ; load into ACCA Before execution Memory CPU B 6 $882 F ACCA $55 99 $8830 3 C $8831 After execution Memory CPU B 6 $882 F ACCA $99 99 $8830 3 C $8831 7

Index Addressing Mode • The effective memory address: = a fixed, 8 -bit, unsigned offset number + contents of Index register (IX or IY). • Instruction accessed memory ($0000) to ($FFFF). • The offset number range from $00 to $FF. Example LDAA $31 , X offset number + ; load contents of memory ($31+IX) ; into ACCA Index register = effective address 8

Example LDAA $31, X ; if IX = $9000 then, contents of ; memory ($9031) load into ACCA. Before execution CPU ACCA $FF IX $9000 Memory 69 $9030 55 $9031 $9032 After execution CPU ACCA $55 IX $9000 Memory 69 $9030 55 $9031 $9032 9

Immediate Addressing Mode • Instruction contains immediate value to load into register. Example: LDAA #$69 ; hex value $69 loaded into ACCA. LDY #$1234 ; hex value $1234 loaded into IY. • Immediate value must be preceded by “#” character. • The immediate value = operand of instruction = operand data of instruction. 10

Example LDAA #$69 ; load value of $69 into ACCA Before execution CPU ACCA $FF Memory After execution CPU Memory ACCA $69 11

Inherent Addressing Mode • Only, opcode used and no operand required. • The operation involves the CPU registers. • The opcode will specify the registers involved. Example: a) TAB ; transfer contents of ACCA to ACCB. b) DEX ; IX = subtract contents of IX by one. ; IX =(IX) - $01 c) DAA ; Decimal Adjust ACCA (BCD) 12

Relative Addressing Mode • Used by branch instructions. (BRA, BHI … ) • The offset ($dd) ranges from -12810 to +12710. Example: BEQ $dd ; if Z flag =“ 0”, ; program executes the next instruction. ; if Z flag =“ 1”, ; program branches & executes ; instruction pointed by (PC + $dd). 13

Example Address PC $8000 PC $8001 $8003 $8023 Machine Code Mnemonics 4 F 27 20 B 7 C 0 00 ----86 29 ----- CLRA BEQ STAA $20 $C 000 LDAA #$29 • Executing BEQ $20 Relative branch to ($8023). • see next page for calculation. 14

Example (contd) • Address ($8001) contains BEQ = Current address. • Address ($8023 = PC + Offset) = Destination address. • The value $20 in (BEQ $20) = Offset. Equation: Destination Address = PC + Offset. = $8003 + $20 = $8023 (Ans. ) 15

Summary of 6 Addressing Modes S/N Addressing Modes Mnemonics Comments 1. Direct LDAA $55 ; memory address ; is 1 byte 2. Extended LDAB $8050 ; memory address ; is 2 bytes 3. Index LDAA $20, X ; index register is ; part of address 16

Summary of 6 Addressing Modes S/N Addressing Modes Mnemonics Comments 4. Immediate LDAB #$55 ; data $55 is ; loaded into ACCB 5. Inherent RTS ; only opcode and ; no data 6. Relative BRA BEGIN ; branch to label ; “BEGIN” 17

Thank You 18