+ All Categories
Home > Documents > Micro 133 Prelim Lecture 4 - Microprocessor_s Addressing Modes

Micro 133 Prelim Lecture 4 - Microprocessor_s Addressing Modes

Date post: 19-Feb-2018
Category:
Upload: keilla-romabiles-leopando
View: 219 times
Download: 0 times
Share this document with a friend

of 25

Transcript
  • 7/23/2019 Micro 133 Prelim Lecture 4 - Microprocessor_s Addressing Modes

    1/25

    MICROPROCESSORS

    ADDRESSING MODESMicro 133: Microprocessor Systems

    Prelim Lecture 4

    by:Engr. Ricrey E. Marquez, CpE, MSCS

  • 7/23/2019 Micro 133 Prelim Lecture 4 - Microprocessor_s Addressing Modes

    2/25

  • 7/23/2019 Micro 133 Prelim Lecture 4 - Microprocessor_s Addressing Modes

    3/25

    Accessing data in high-level language suchC, C++, or Pascal

    C = A + B

    Accessing data in DEBUG or Assembly

    MOV AX,[0200] ;the A value

    MOV BX, [0202] ;the B value

    ADD AX, BX ; A + B

    MOV [0300], AX ;store result at C

    Choice of addressing mode used depends upon the type of data being

    accessed.

    A constant,

    A variablepiece o i!or"atio! or

    A! ite" #ithi! a! array of data$

    INTRODUCTION TO ADDRESSING

    MODESMICROPROCESSORS ADDRESSING MODES

  • 7/23/2019 Micro 133 Prelim Lecture 4 - Microprocessor_s Addressing Modes

    4/25

    Intel family supportsfouraddressing modes (in general)

    Modes differ in the location data and address calculations

    All nodes involvesphysical addressgeneration

    8086 Instruction Syntax

    Lines of code

    Label:Instruction ;Comment/s

    InstructionOpcode [operand 1], [operand 2]Mnemonic Destination Source

    8088/8086 INSTRUCTION SYNTAXMICROPROCESSORS ADDRESSING MODES

  • 7/23/2019 Micro 133 Prelim Lecture 4 - Microprocessor_s Addressing Modes

    5/25

    OperandsThese are destination address and source address of

    data.

    Opcode(Operation code)This tells the microprocessor which operation to perform

    The way in which these addresses are specified is

    named the addressing mode for thesourceanddestinationaddress.

    Source operandis to the right

    Destination operandis to the left

    8088/8086 INSTRUCTION SYNTAXMICROPROCESSORS ADDRESSING MODES

  • 7/23/2019 Micro 133 Prelim Lecture 4 - Microprocessor_s Addressing Modes

    6/25

    Data Addressing Modes Register Addressing Mode (General)

    Immediate Addressing Mode (Constant)

    Memory Addressing Modes Direct Addressing Mode (Variable)

    Register Indirect Addressing Mode (Arrays)

    Base-plus-Index Addressing Mode (Complex Array)

    Register Relative Addressing Mode (Complex Array)

    Base-Relative-plus-Index Addressing Mode (More Complex Array)

    Scaled-index Addressing Mode (More Complex Array for 32 bit)

    Program Memory Addressing Modes Direct Program Memory Addressing Mode

    Register Indirect Program Memory Addressing Mode

    Memory Indirect Program Memory Addressing Mode

    Relative Program Memory Addressing Mode (Conditional)

    Stack Memory Addressing Modes

    TYPES OF PS ADDRESSING

    MODESMICROPROCESSORS ADDRESSING MODES

  • 7/23/2019 Micro 133 Prelim Lecture 4 - Microprocessor_s Addressing Modes

    7/25

    Register Addressing Mode (General)

    It uses the name of a register to identify the location of data the

    data is held in the register.

    Copy the content source register to a destination register

    8 Working Registers AX, BX, CX, DX, SI, DI, BP, SP 16 bit wide.

    Four of the registers AX, BX, CX, DXcan be thought of as single

    16 bit registers or dual 8 bit registers.

    Length of the registers must match

    MOV AX, CX

    MOV BL, CL

    MOV AL, SI ;ILLEGAL

    MOV AX, CH ;ILLEGAL

    MOV DS, AX

    MOV CS, AX ;ILLEGAL

    DATA ADDRESSING MODESMICROPROCESSORS ADDRESSING MODES

  • 7/23/2019 Micro 133 Prelim Lecture 4 - Microprocessor_s Addressing Modes

    8/25

    Immediate Addressing Mode (Constant)

    Transfer data (constant) to into a destination register

    Value moved into a register (from instruction)

    Most instructions assume that the operands of an instruction are the address of the

    data involved, not the data itself.

    The exception to this rule is the immediate addressing mode, where the actual datanumber is specified in the instruction and is hard coded as part of the instruction

    (source operand).

    ITEM E!" #$%H

    ITEM& E!" ########B

    ITEM% E!" #D

    STA'T( MOV AX, ITEMMOV BL, )*D

    MOV CH, ITEM& ; ILLEGAL

    MOV #CDH, BL ; ILLEGAL

    MOV ITEM&, AL ; ILLEGAL

    Note:EQUdirective assigns names to constant numbers and does not save memory space

    DATA ADDRESSING MODESMICROPROCESSORS ADDRESSING MODES

  • 7/23/2019 Micro 133 Prelim Lecture 4 - Microprocessor_s Addressing Modes

    9/25

    Labels -These are names given to an address of anopcodein code memory

    Constants -These are names assigned to absolutely constant numbers, hard coded into

    instructions

    Variables

    These are names of an address in memory However, a program reference to the variable name, as an operand, will use the contents of address

    LOO+HE'E( MOV AX,BX

    -M+ LOO+HE'E

    CO. E!" #ABCDH

    MOV AX,CO.

    VA' D/ #ABCDH

    MOV AX,VA'

    MOV VA',BX

    SOME SYMBOLS USED IN

    ADDRESSING MODEMICROPROCESSORS ADDRESSING MODES

  • 7/23/2019 Micro 133 Prelim Lecture 4 - Microprocessor_s Addressing Modes

    10/25

    Accessing data that is in memory is done by specifying

    the address of the data.Addressis actually the offset of the data relative to the base

    of the data segment.

    This mode is invoked when the operand is placed in

    square brackets[xxxx].

    Direct Memory Addressing Mode(Variable)

    Move byte or word between memory location and a register

    Memory address appears in the instructions instead of data

    Data accessed from a location in memory

    [xxxx]is afixed addressnumber

    MEMORY ADDRESSING MODESMICROPROCESSORS ADDRESSING MODES

  • 7/23/2019 Micro 133 Prelim Lecture 4 - Microprocessor_s Addressing Modes

    11/25

    Examples of Direct Addressing Modes

    MOV 0&%1H2, AX ;MOVE CONTENT OF AX TO

    ;DS:1234H; NOT ;SUPPORTED!

    VA' D/ 3

    VA'& DB #$$H

    MOV VA',&%1H ;MOVE NUMBER 1234H TO

    ;VARIABLE VAR1

    MOV 0VA'2,AX

    MOV VA'4,&%1H

    MOV /O'D +T' 0VA'42,&%1H

    MOV B5TE +T' 0VA'2,&H

    MOV VA'&,&%1H

    MOV AH,VA'&

    MEMORY ADDRESSING MODESMICROPROCESSORS ADDRESSING MODES

  • 7/23/2019 Micro 133 Prelim Lecture 4 - Microprocessor_s Addressing Modes

    12/25

    Register Indirect Addressing Mode (Arrays)

    Transfer data between a register and a memory location

    address by a register

    Sometimes need using the special assembler directiveswhen size is not clear such asBYTE PTR, WORD

    PTR, DWORD PTR.

    VA'DD &%167*)H

    VA'&DD 8ABCDE$#H

    S"M DD 3

    ;MOVE LOW WORD OF VAR1 TO AX

    STA'T( MOV AX, /O'D +T' 0VA'2

    ;MOVE LOW WORD OF VAR2 TO BX

    MOVBX, /O'D +T' 0VA'&2

    MEMORY ADDRESSING MODESMICROPROCESSORS ADDRESSING MODES

  • 7/23/2019 Micro 133 Prelim Lecture 4 - Microprocessor_s Addressing Modes

    13/25

    MOV CX, /O'D +T' 0VA'4&2

    ;MOVE LOW WORD OF VAR1 TO AX

    MOV DX, /O'D +T' 0VA'&4&2

    ;ADD THE LOW WORDS

    ADD AX, BX ;ADD THE HIGH WORDS

    ADC CX, DX

    ;MOVE LOW WORD OF RESULT TO LOW WORD

    ;OF SUM

    MOV /O'D +T' 0S"M2, AX

    ;MOVE HIGH WORD OF RESULT TO HIGH

    ;WORD OF SUM

    MOV /O'D +T' 0S"M4&2, CX

    'ET

    MEMORY ADDRESSING MODESMICROPROCESSORS ADDRESSING MODES

  • 7/23/2019 Micro 133 Prelim Lecture 4 - Microprocessor_s Addressing Modes

    14/25

    Base-plus-Index Addressing Mode

    (Complex Array)

    Transfer data between a register and amemory location addressed by base register

    and index register

    MOV 0BX4SI2,AX

    MOV DX,0BX4DI2

    MEMORY ADDRESSING MODESMICROPROCESSORS ADDRESSING MODES

  • 7/23/2019 Micro 133 Prelim Lecture 4 - Microprocessor_s Addressing Modes

    15/25

    Register Relative Addressing

    Mode (Complex Array)

    Move data between a register and a

    memory location addressed by specified

    register plus displacement (offset)

    MOV AX,0BX412

    MOV BX,0S+4%2

    MEMORY ADDRESSING MODESMICROPROCESSORS ADDRESSING MODES

  • 7/23/2019 Micro 133 Prelim Lecture 4 - Microprocessor_s Addressing Modes

    16/25

    Base-Relative-plus-Index Addressing

    Mode (More Complex Array)

    Transfer data between a register and amemory location addressed by base and index

    register plus displacement

    MOV 0BX4SI4&2,AX

    MOV DX,0BX4DI412

    MEMORY ADDRESSING MODESMICROPROCESSORS ADDRESSING MODES

  • 7/23/2019 Micro 133 Prelim Lecture 4 - Microprocessor_s Addressing Modes

    17/25

    Scaled-index Addressing Mode (More

    Complex Array for 32 bit)

    The address in the second register is modified by

    scale factor

    Scale factor are 1, 2, 4, or 8 for word, double word, or

    quad-word access respectively.

    Only available in 80386 and above microprocessor (32

    bit)

    MOV 0EBX4&9ECX2, AX

    MOV EAX, 0EB+4)9ECX2

    MEMORY ADDRESSING MODESMICROPROCESSORS ADDRESSING MODES

  • 7/23/2019 Micro 133 Prelim Lecture 4 - Microprocessor_s Addressing Modes

    18/25

    The flow of a program can be controlled through

    the use of differentbranching instructions

    Different addressing modes are also used here to

    direct the CPU to various locations of program

    code

    Direct Program Memory Addressing ModeJump to a location specified by a constant

    -M+ #E##: ;JUMPS DIRECTLY TO CS:E1H

    PROGRAM MEMORY ADDRESSING

    MODESMICROPROCESSORS ADDRESSING MODES

  • 7/23/2019 Micro 133 Prelim Lecture 4 - Microprocessor_s Addressing Modes

    19/25

    Register Indirect Program Memory Addressing

    ModeJump to a location specified by the contents of a register

    -M+ BX ;J"#$ %& %'( )**+($$ ,&-%).-(* .- BX

    Memory Indirect Program Memory Addressing

    ModeJump to a location given by the contents of two memory

    locations pointed at by a register

    -M+ 0DI2 ;REPLACES IP WITH THE CONTENTS OF THE

    ;MEMORY LOCATIONS POINTED

    ;AT BY DI AND DI / 1

    PROGRAM MEMORY ADDRESSING

    MODESMICROPROCESSORS ADDRESSING MODES

  • 7/23/2019 Micro 133 Prelim Lecture 4 - Microprocessor_s Addressing Modes

    20/25

    Relative Program Memory Addressing Mode

    (Conditional)

    Jump according to some condition to a memory

    location that is within128 or +127 bytesof thecurrent location

    -E;-

  • 7/23/2019 Micro 133 Prelim Lecture 4 - Microprocessor_s Addressing Modes

    21/25

    Stackis LIFO (LastIn,FirstOut) in the memory

    Data are place byPUSHand removed byPOP

    instruction

    Stack memory is maintained by stack segment (SS) andstack pointer (SP) SS:SP

    When a word ispushed,high 8-bitsare stored atSP-1

    andlow 8-bitsare stored atSP-2, thenSPisdecremented

    by 2

    When a word ispoped,low 8-bitsare removed from the

    locationSPandhigh 8-bitsare removed from the location

    address bySP+1, atSP-2, thenSPisincremented by 2

    STACK MEMORY ADDRESSINGMICROPROCESSORS ADDRESSING MODES

  • 7/23/2019 Micro 133 Prelim Lecture 4 - Microprocessor_s Addressing Modes

    22/25

    STACK MEMORY ADDRESSINGMICROPROCESSORS ADDRESSING MODES

    Figure 1+"SH BX - place the contents of BX onto a stack

  • 7/23/2019 Micro 133 Prelim Lecture 4 - Microprocessor_s Addressing Modes

    23/25

    STACK MEMORY ADDRESSINGMICROPROCESSORS ADDRESSING MODES

    Figure 2+O+ CX removed data from the stack and

    place them intoCX

  • 7/23/2019 Micro 133 Prelim Lecture 4 - Microprocessor_s Addressing Modes

    24/25

    Normally a complete program is written as a set of subroutines

    To execute a subroutine aCALLinstruction is used

    CALLis similar to aprocedure callin a high-level language

    When executed it pushes IP and the return segment (forFAR calls) onto the stack, then

    executes a jump to the call address

    Two types of CALLs can be executed

    CALLto aNEARaddress Only Offset (IP) specified, segment assumed to be the same

    CALLto aFARaddress New Segment and Offset (IP) specified

    CALLsubroutine is terminated with aRETinstruction

    RET(RETurn) instruction causes the CPU to pop the RETURN address off the stack (IP

    or Segment and IP) and execute a jump back to it

    CALL ##

    CALL #&8(##

    CALLING SUBROUTINESMICROPROCESSORS ADDRESSING MODES

  • 7/23/2019 Micro 133 Prelim Lecture 4 - Microprocessor_s Addressing Modes

    25/25

    If the subroutine is situated in the same segment

    as the routine that it has been called from, then

    the subroutine is considered to beNEAR.

    If the subroutine is not situated in the same

    segment as the routine that it has been called

    from, then the subroutine is considered to be

    FAR.

    Jump to a location out of the current code segment,

    meaning that not only IP but also CS is replaced with

    new values

    FAR VS NEAR SUBROUTINE

    DIRECTIVESMICROPROCESSORS ADDRESSING MODES


Recommended