190 likes | 405 Views
Microcontroller Fundamentals & Programming. Addressing Modes. Addressing Modes. Addressing Modes define the different methods, instructions obtain data required for its execution. What are 68hc11 instructions ? Examples: LDAA #$55 LDAA $20,X LDAB $2000
E N D
Microcontroller Fundamentals & Programming Addressing Modes
Addressing Modes • Addressing Modesdefine the different methods, instructions obtain data required for its execution. • What are 68hc11 instructions ? • Examples: LDAA #$55 LDAA $20,X LDAB $2000 BRA BEGIN Some 68HC11 instructions.
Types of Addressing Modes • The 68HC11 has 6addressing modes: • Direct • Extended • Index • Immediate • Inherent • Relative
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
CPU ACCA $FF Example LDAA $30 ; contents of memory ($0030) ; load into ACCA. Before execution After execution Memory Memory CPU B6 $002F 55$0030 3C $0031 B6 $002F 55 $0030 3C $0031 ACCA $55
Op-code Operand (2-bytes) 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 $8830 ; contents of memory ($8830) ; loaded into ACCA
CPU ACCA $55 Example LDAA $8830 ; contents of memory ($8830) ; load into ACCA After execution Before execution Memory Memory CPU B6 $882F 99$8830 3C $8831 B6 $882F 99 $8830 3C $8831 ACCA $99
Index Addressing Mode • The effective memory address: • = afixed, 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 ; load contents of memory ($31+IX) ; into ACCA + effective address = offset number Index register
Memory Memory CPU CPU ACCA $FF ACCA$55 69 $9030 55 $9031 $9032 69 $9030 55 $9031 $9032 IX $9000 IX $9000 Example LDAA $31,X ; if IX = $9000 then, contents of ; memory ($9031) load into ACCA. Before execution After execution
Immediate Addressing Mode • Instruction contains immediate value to load into register. • Immediate value must be preceded by “#” character. • The immediate value = operand of instruction =operand data of instruction. Example: LDAA ; hex value $69 loaded into ACCA. LDY ; hex value $1234 loaded into IY. #$69 #$1234
Example LDAA #$69 ; load value of $69 into ACCA Before execution After execution Memory Memory CPU CPU ACCA $FF ACCA$69
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) Inherent Addressing Mode • Only, opcode used and no operand required. • The operation involves the CPU registers. • The opcode will specify the registers involved.
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).
AddressMachine CodeMnemonics $8000 4F CLRA $8001 27 20 BEQ $20 $8003 B7 C0 00 STAA $C000 - - - - - - - - - - $8023 86 29 LDAA #$29 - - - - - PC PC Example • Executing BEQ $20 Relative branch to ($8023). • see next page for calculation.
Example (contd) • Address ($8001) contains BEQ = Current address. • Address ($8023 = PC + Offset) = Destination address. • The value $20 in (BEQ $20) = Offset. Equation: Destination = PC + Offset. Address = $8003 + $20 = $8023 (Ans.)
Summary of 6 Addressing Modes • Addressing • S/NModesMnemonicsComments • Direct LDAA $55 ; memory address ; is 1 byte • Extended LDAB $8050 ; memory address ; is 2 bytes • Index LDAA $20,X ; index register is ; part of address
Summary of 6 Addressing Modes • Addressing • S/NModesMnemonicsComments • Immediate LDAB #$55 ; data $55 is ; loaded into ACCB • Inherent RTS ; only opcode and ; no data • Relative BRA BEGIN ; branch to label ; “BEGIN”