ECE 511: Digital System & Microprocessor

Slides:



Advertisements
Similar presentations
Instruction Set Design
Advertisements

Assembly Language Programming
1/1/ / faculty of Electrical Engineering eindhoven university of technology Introduction Part 2: Data types and addressing modes dr.ir. A.C. Verschueren.
Address Indirect Addressing with Index and Displacement – Mode 6 Opcode - 4dRn - 3dmd - 3sMS - 6 rt - 1xm - 3s -1und - 3 displacement - 8 rt – type of.
9/20/6Lecture 3 - Instruction Set - Al Instruction Set.
Microprocessor Fundamentals Week 5 Mount Druitt College of TAFE Dept. Electrical Engineering 2008.
Chapter 11 Instruction Sets
Data Transfer Group ECE 511: Digital System & Microprocessor.
TK 2633 Microprocessor & Interfacing
68k Software Model ECE511: Digital System & Microprocessor.
Exception Processing ECE511: Digital System & Microprocessor.
TK 2633 Microprocessor & Interfacing Lecture 3: Introduction to 8085 Assembly Language Programming (2) 1 Prepared By: Associate Prof. Dr Masri Ayob.
Room: E-3-31 Phone: Dr Masri Ayob TK 2633 Microprocessor & Interfacing Lecture 1: Introduction to 8085 Assembly Language.
Room: E-3-31 Phone: Dr Masri Ayob TK 2633 Microprocessor & Interfacing Lecture 1: Introduction to 8085 Assembly Language.
8051 ASSEMBLY LANGUAGE PROGRAMMING
Unit -II CPU Organization By- Mr. S. S. Hire. CPU organization.
EET 2261 Unit 2 HCS12 Architecture
Computer Architecture
Architecture of the MSP430 Processor. Central Processing Unit Program Counter (PC) - Contains the address of the next instruction to be executed. The.
Part II: Addressing Modes
CEG 320/520: Computer Organization and Assembly Language ProgrammingFlow Control 1 Flow Control.
Lecture 18 Last Lecture Today’s Topic Instruction formats
Module 10 Adapted By and Prepared James Tan © 2001.
CEG 320/520: Computer Organization and Assembly Language ProgrammingIntel Assembly 1 Intel IA-32 vs Motorola
ME4447/6405 The George W. Woodruff School of Mechanical Engineering ME4447/6405 Microprocessor Control of Manufacturing Systems and Introduction to Mechatronics.
Execution of an instruction
COMPUTER ARCHITECURE INSTRUCTION SET ARCHITECTURE.
9/20/6Lecture 2 - Prog Model Architecture, Data Types and Addressing Modes.
Addressing Modes1 Addressing modes are concerned with how the CPU accesses the operands used by its instructions.
ECEG-3202 Computer Architecture and Organization Chapter 6 Instruction Sets: Addressing Modes and Formats.
8086 Internal Architecture
1 ECE 372 – Microcontroller Design Assembly Programming HCS12 Assembly Programming Addressing Modes Stack Operations Subroutines.
INTRODUCTION Programming – process of composing several instructions to perform certain tasks. Program – product of programming which contains several.
Topics covered: Instruction Set Architecture CSE243: Introduction to Computer Architecture and Hardware/Software Interface.
68k Software Model ECE511: Digital System & Microprocessor.
Lec. 7 Introduction to Assembly Programming Dr. Tamer Samy Gaafar Microprocessors.
ECE 447: Lecture 11 Introduction to Programming in Assembly Language.
M68k Arithmetic Instructions ECE 511: Digital System & Microprocessor.
MicroProcessors Lec. 3 Dr. Tamer Samy Gaafar. Course Web Page
1 ADDRESSING MODES Addressing Modes: * Specifies a rule for interpreting or modifying the address field of the instruction (before the operand is actually.
Computer Architecture
Logical, Shift, Rotate & BCD. What we will learn in this session: Logical instructions. Shift & Rotate instructions. BCD operations. Bit operations.
M68k Addressing Modes ECE 511: Digital System & Microprocessor.
Displacement (Indexed) Stack
Addressing Modes the addressing mode defines how data is accessed
ECE 3430 – Intro to Microcomputer Systems
Figure 8.1 of course package
ECE 3430 – Intro to Microcomputer Systems
Chapter 11 Instruction Sets
Alvaro Mauricio Peña Dariusz Niworowski Frank Rodriguez
Microcomputer Programming
William Stallings Computer Organization and Architecture 8th Edition
Assembly Lang. – Intel 8086 Addressing modes – 1
Computer Organization and Assembly Language (COAL)
Processor Organization and Architecture
EECE-276 Fall 2003 Microprocessors & Microcontrollers II
Lecture 3 - Instruction Set - Al
Introduction to Assembly Language
ME4447/6405 Microprocessor Control of Manufacturing Systems and
ECEG-3202 Computer Architecture and Organization
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
8085 MICROPROCESSOR 8085 CPU Registers and Status Flags S Z AC P C A B
68000 Architecture, Data Types and Addressing Modes
M68k Arithmetic Instructions
CNET 315 Microprocessor & Assembly Language
Assembly Language Programming
William Stallings Computer Organization and Architecture 8 th Edition Chapter 11 Instruction Sets: Addressing Modes and Formats.
ECE511: Digital System & Microprocessor
Presentation transcript:

ECE 511: Digital System & Microprocessor M68k Addressing Modes ECE 511: Digital System & Microprocessor

What we will learn in this session: M68k addressing modes: How to access data: In registers. In memory. Available addressing modes. When to use what.

Introduction

Introduction All CPU instructions have similar requirements: Action - What action should it perform? Source - Where is the data that it is supposed to process? Target - Where should it put the results? Action is done using instructions. Addressing modes identify source and target.

Addressing Modes Methods to access data inside: CPU registers. Memory. M68k allows 14 addressing modes: Direct reference. Indirect reference. Addressing modes allow flexible & effective programs design.

Address Register Indirect ARI + PostIncrement Register Addressing Mode ARI + Predecrement ARI + Displacement Data Register Direct ARI + Index Address Register Direct Absolute Short Address Absolute Long Address AM PC with Displacement PC with Index Immediate Data Mem. Addressing Mode Quick Immediate Data Implied Addressing

Register Addressing Modes

Register Addressing Modes Modes to access registers in M68k: Address Register. Data Register. Consists of 2 methods: Data Register Direct (DRD). Address Register Direct (ARD).

DRD (Data Register Direct) Used to access data registers. Represented to as Dn: D represents data register. n is register number. From D0 to D7.

DRD Example MOVE.B D0,D1 ADD.W D4,(A0) MULU D5,D7

ARD (Address Register Direct) Used to access address registers. Referred to as An: A represents address register. n is register number. From A0 to A7. A7 = stack pointer.

ARD Example MOVEA.L A0,A4 ADDA.W A3,A6 MOVEA.W #$1234,A2

Memory Addressing Modes

Memory Addressing Modes Modes to access memory locations. 12/14: Memory space is large area. Many varieties of addressing modes. Depends on desired function.

ARI (Address Register Indirect) Refers to contents of memory location pointed by An. Address register enclosed in parenthesis  (An).

Example: ARI D0 = $12345678 A1 = $007A92 MOVE.B D0,(A1) (This command does not move the data inside D0 into A1, but moves the data inside D0 into the memory location pointed by A1).

Example: ARI MOVE.B D1,(A4) ADD.W (A3),D3 Moves a byte from D1 into the memory location specified by A4. ADD.W (A3),D3 Adds the word content of memory address specified by A3 to data register D3.

Example: ARI D0 = $12345678 A1 = $00007A92 MOVE.L D0,(A1) Memory Contents $7A90 $7A91 $7A92 $12 $7A93 $34 D0.L = $12345678 $7A94 $56 $7A95 $78 A1 = $007A92 (A1 is still unchanged).

ARI + PI (Address Register Indirect with Post-Increment) Same as ARI, but An automatically incremented after execution (post-increment). Use the ‘+’ sign after (An). Useful in for loops.

ARI + PI (Address Register Indirect with Post-Increment) Increment value depends on data length: If .B is used, An is incremented by 1. If .W is used, An is incremented by 2. If .L is used, An is incremented by 4.

Example 1: ARI + PI D0 = $12345678 A1 = $001002 MOVE.W D0,(A1)+ Memory Content $1001 $1002 $56 $1003 $78 D0 = $12345678 $1004 $1005 After execution, A1 is incremented by 2 since .W was used. $1006 A1 = $1002 + 2 = $001004 (new value).

Example 2: ARI + PI D0 A0 5 $1000 4 $1001 3 $1002 2 $1003 A1 $2000 D0 = $00000005 *as counter A0 = $001000 A1 = $002000 LABEL1 MOVE.B (A0)+,(A1)+ SUB.B #1,D0 CMP #0,D0 BNE LABEL1 D0 A0 5 $1000 4 $1001 3 $1002 2 $1003 A1 $2000 $2001 $2002 $2003 1 $1004 $2004 $1005 $2005

ARI + PD (Address Register Indirect with Pre-Decrement) Same as ARI, but value in address register automatically decremented before execution (pre-decrement). Use the ‘-’ before (An) sign. Useful to push data to stack.

ARI + PD (Address Register Indirect with Pre-Decrement) The increment value depends on data length: If .B is used, An is decremented by 1. If .W is used, An is decremented by 2. If .L is used, An is decremented by 4.

Example: ARI + PD – Moving Data to Stack MOVE.B D0,-(A7) Memory Contents A7 (SP) $1001 $78 Before execution, A7 is decremented by 1 since .B was used. $1002 A7 = $1002 - 1 = $001001 (new value). $1003 $1004 D0 = $12345678 $1005 $1006

ARI + D (Address Register Indirect with Displacement) Adds a displacement value to ARI. Format: d(An) An is address register. d is 16-bit displacement value. -32,768 ($8000) ≤ d ≤ 32,767 ($7FFF)

Example: ARI + D D3 = $12345678 A4 = $004500 MOVE.B D3,$750(A4) Memory Contents $4C4C $4C4D $4C4E A4=$004500, Disp.=$750 Effective Address: A4 $004500 D $000750 + EA $004C50 $4C4F $4C50 $78 $4C51

Example: ARI + D D3 = $00000000 A4 = $004500 MOVE.B $FFF3(A4),D3 Memory Contents $44F1 $11 $44F2 $22 $44F3 $33 $FFF3 is negative (MSB = 1) 2’s complement = $000D $44F4 $44 $44F5 $55 Effective Address: A4 $004500 Disp. $00000D – $0044F3 $44F6 $66 D3 = $00000033

Example: ARI + D D3 = $00000000 A4 = $004500 MOVE.B -5(A4),D3 Memory Contents $44F9 $44FA $44FB $14 $44FC $44FD Effective Address: A4 $004500 Disp. $000005 – $0044FB $44FE D3 = $00000014

ARI + D Example MOVE.B D1,34(A0) ADD.B $1254(A2),D4 Displacement must not be more than 16-bits long.

ARI + I (Address Register Indirect with Index) Similar to ARI + D, but adds another index term. Displacement range $80 (-128) < D < $7F (127). Index term from Dn or An. Used for implementing 2-D arrays. Adds index term into bracket: D(An,Dn.W) D(An,An.W) Effective address is ARI + D + Index (Dn.W or An.W).

ARI + I Example MOVE.B D1,34(A0,D3.W) ADD.B $54(A2,A4.W),D4 Displacement must be 8-bits long. Index must be 16-bits long.

ARI + I Example D1 = $00000012 A4 = $00001000 MOVE.B #$FF,$78(A4,D1.W) Effective Address (ARI + D + I): $1088 $1089 ARI $00001000 + D1.W $ 0012 + D $ 78 EA $0000108A $108A $FF $108B $108C $108D $108E

ALA (Absolute Long Address) Directly addresses memory locations. Address must be 24-bits. No sign extension performed. Slower than ASA, requires more machine code.

ALA Example MOVE.L D0,$100100 ADD.B $001000,D3 MOVE.B $000100,$400400

Example: ALA MOVE.B $001000,D0 ADD.W $400400,D1 MOVE.L D4,$003000 Moves byte content of memory address $1000 to D0. ADD.W $400400,D1 Adds the word content of $400400 to D1. MOVE.L D4,$003000 Moves a long-word from D4 to address $3000. *Address length must always be 24-bits

Absolute Long Address D1 = $00000000 MOVE.W $001000,D1 Memory $1000 $12 1 2 3 4 D1 = $1001 $34 $1002 $FF $1003 $56 $1004 $AA $1005 $AC $1006 $12

Absolute Short Address Used to directly address data in two memory ranges: $000000 to $007FFF. $FF8000 to $FFFFFF. Only specify 16-bit address, automatically sign-extended to 24-bits. Requires less machine code than ALA. Be careful with sign-extension.

Example: Absolute Short Address SUB.B $4601,D4 4 6 0 1 0100 0110 0000 0001 0 0 4 6 0 1 0000 0000 0100 0110 0000 0001 MSB is 0 sign-extended to 24-bits E.A. is $004601 Will subtract the byte value in address $004601 from D4

Example: Absolute Short Address MOVE.B $8432,D3 8 4 3 2 1000 0100 0011 0010 F F 8 4 3 2 1111 1111 1000 0100 0011 0010 MSB is 1 sign-extended to 24-bits E.A. is $FF8432 Will move byte value from address $FF8432 to D3.

ASA vs. ALA MOVE.B $8432,D3 and MOVE.B $FF8432,D3 are equal, but MOVE.B $8432,D3 executes faster & uses less memory space.

PC + D (Program Counter with Displacement) Similar to ARI + D, but An replaced with PC. Allows flexible program placement: Can be put anywhere in memory. Address referred relative to PC. Would still run even with different starting addresses.

Program Counter with Displacement Format: d(PC) PC is program counter. d is 16-bit displacement value. 16 bit displacement: -32,768 ($8000) ≤ d ≤ 32,767 ($7FFF) Displacement must be properly calculated during program design.

Why PC + D allows flexible addressing? Data #1 Data #2 Data #1 is located 3 memory locations above Instruction #1 Data #2 is located 2 memory locations above Instruction #1 Data #3 Instruction #1 Instruction #2 Instruction #3 … … Instruction #n In PC + D, the location of data is always stated as relative to instruction.

Why PC + D allows flexible addressing? Data #1 Data #2 Data #3 Instruction #1 PC Instruction #2 Instruction #3 … … Instruction #n When the program is run, PC is incremented as instructions are executed.

Why PC + D allows flexible addressing? Data #1 Data #2 Data #3 Instruction #1 Instruction #2 Instruction #3 … Instruction #n Data #1 is located 3 memory locations above PC Data #2 is located 2 memory locations above PC When program running, data location referred to PC.

Wherever you put the program, PC-relative addressing always refers to the right location. Address Space Address Space Address Space Data #1 Data #2 Data #3 Instruction #1 Instruction #2 Instruction #3 … Instruction #n Data #1 is located 3 memory locations above PC Data #1 Data #2 Data #3 Instruction #1 Instruction #2 Instruction #3 … Instruction #n Data #1 is located 3 memory locations above PC Data #1 Data #2 Data #3 Instruction #1 Instruction #2 Instruction #3 … Instruction #n Data #1 is located 3 memory locations above PC *Assuming PC @ Instruction #1

PC + D Example PC = $004000 D1 = $12345678 MOVE.B $32(PC),D1 Memory $4031 $12 $4032 $23 Effective Address: PC = $004000 D = $ 32 EA = $004032 $4033 34 $4034 $45 $4035 $56 + $4036 $67 D1 = 1 2 3 4 5 6 2 3

PC + I (Program Counter with Index) Similar to ARI + I, but An replaced with PC. Allows similar flexibility as PC + D. Format: d(PC,Dn) d(PC, An) PC is program counter. d is 8-bit displacement value.

PC + I (Program Counter with Index) 8-bit displacement: -128 ($80) ≤ d ≤ 127 ($7F) Displacement must be properly calculated during program design.

PC + I Example D1 = $00000388 PC = $00003000 MOVE.B #$A2,$FA(PC,D1.W) *$FA = -6 (2’s complement) Effective Address (PC + D + I): $3380 $3381 ARI $00003000 + D1.W $ 0388 - D $ 06 EA $00003382 $3382 $A2 $3383 $3384 $3385 $3386

Immediate Data Used to transfer constant values into registers/memory locations. Consists of 2 parts: The constant value. The register/memory location to store it in. Symbol ‘#’ must be put in front of the constant value.

Types of Constant Symbol Data Type Example % Binary #%01101010 @ Octal @123 <none> Decimal #45 $ Hexadecimal #$35 ‘ ’ Character #’B’

Example: Moving Decimal Value to Data Register D0 = $FFFFFFFF MOVE.B #12,D0 Constant value: 12D = #$0C F D0 = C Final D0 =

Example: Moving Hex Value to Memory MOVE.W #$1234,$004000 Constant value: $1234 (hex) Target: memory address $4000. $3FFE … $3FFF $4000 $12 $4001 $34 $4002 Memory Address:

Example: Moving Hex Value to Address Register MOVEA.L #$00400400,A3 Constant variable: 00400400 (hex) Target: A3. A3 = $00400400

Example: Moving Hex Value to Memory MOVE.W #$1234,$004000 Constant value: $1234 (hex) Target: memory address $4000. $3FFE … $3FFF $4000 $12 $4001 $34 $4002 Memory Address:

Example: Moving Character Value to Memory MOVE.L #’BUKU’,D0 ‘B’ = $42, ‘U’ = $55, ‘K’ = $4B, ‘U’ = $55 Target: D0. 4 2 5 5 4 B 5 5 D0 = ‘B’ ‘U’ ‘K’ ‘U’

Example: Moving Binary Value to Memory MOVE.B #%10101011,D0 %1010 = $A, %1011 = $B Target: D0. A B D0 =

Quick Immediate Data Similar to ID, but can only transfer 1 byte. Byte is sign-extended to 32-bits. Used together with MOVEQ instruction. Can only be used for Dn.

Example: Quick Immediate Data MOVEQ #$05,D1 Constant variable: 05 (hex) Target: D1. D1 = $00000005 $05 = 0000 0101 (MSB is 0) Sign-extended to 32-bits

Example: Quick Immediate Data MOVEQ #$EA,D0 Constant value: EA (hex) Target: D0. D0 = $000000EA D0 = $FFFFFFEA $EA = 1110 1010 (MSB is 1) Sign-extended to 32-bits

Example: Quick Immediate Data D1 = $FFFFFFFF MOVEQ #$05,D1 Constant value: 05 (hex) Target: D1. D1 = $FFFFFF05 D1 = $00000005 $05 = 0000 0101 (MSB is 0) Sign-extended to 32-bits

Implied Addressing Uses mnemonics to refer to M68k’s internal registers. Examples: SR – Status Register USP – User Stack Pointer. SSP – Supervisor Stack Pointer. CCR – Condition Code Register TRAPV – Trap exception if V-bit set.

IA Example – Set Trace Mode ORI.W #$8000,SR T S I2 I1 I0 X N Z V C 1 1 1 OLD SR= 1 OR 1 1 1 1 NEW SR= Sets trace mode to on (T = 1), other bits unchanged.

IA Example – Clear CCR ANDI.B #$00,CCR Clears all bits in CCR X N Z V C 1 1 1 OLD CCR = AND NEW CCR = Clears all bits in CCR

Conclusion

We have covered these addressing modes ARI (An) ARI+PI (An)+ ARI+PD -(An) ARI+D D(An) ARI+I D(An,Dn/An.s) PC+D D(PC) PC+I D(An,Dn/An.s) ALA $001001 ASA $FFAA IA CCR, SR Effective Address: <ea> DRD D0  D7 ARD A0  A7 Dn and An ID #($ % @ ‘’) Immediate data: <id>

Conclusion Addressing modes allow flexibility in accessing registers memory locations. Try to understand how to calculate EA: ARI (PI, PD, D, I) PC (D, I) The rest are straightforward.

Please read: Antonakos, pg. 47-58 The End Please read: Antonakos, pg. 47-58