0% found this document useful (0 votes)
4 views30 pages

Microprocessor Week 3

The document discusses various addressing modes used in microprocessors, including data addressing modes such as register, immediate, direct, and indirect addressing. It also covers program memory addressing modes like direct, relative, and indirect addressing, as well as stack memory addressing which utilizes PUSH and POP instructions. Additionally, it explains effective address calculation and the differences between near and far calls in procedures.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views30 pages

Microprocessor Week 3

The document discusses various addressing modes used in microprocessors, including data addressing modes such as register, immediate, direct, and indirect addressing. It also covers program memory addressing modes like direct, relative, and indirect addressing, as well as stack memory addressing which utilizes PUSH and POP instructions. Additionally, it explains effective address calculation and the differences between near and far calls in procedures.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

Week 3

Microprocessor
Addressing Modes
EFFİCİENT SOFTWARE DEVELOPMENT MOV (MOVE DATA) İNSTRUCTİON WİLL CALL AND JUMP İNSTRUCTİONS WİLL BE PUSH AND POP İNSTRUCTİONS WİLL BE
FOR THE MP REQUİRES A COMPLETE BE USED TO DESCRİBE THE DATA USED TO DESCRİBE PROGRAM MEMORY USED TO DESCRİBE THE OPERATİON OF
FAMİLİARİTY WİTH THE ADDRESSİNG ADDRESSİNG MODES. ADDRESSİNG MODES. THE STACK MEMORY.
MODES EMPLOYED BY EACH
İNSTRUCTİON.
• Because the MOV
instruction is a very
Data common and flexible
instruction, it provides a
Addressing basis for the explanation
of the data-addressing
Modes modes.
• Figure below illustrates
the MOV instruction and
defines the direction of
data flow.
The source is to the right and the
destination is to the left, next to the
This direction of flow, which is applied
opcode MOV. (An opcode, or operation
to all instructions, is awkward at first.
code, tells the microprocessor which
operation to perform.)
• We naturally assume that things move
from left to right, whereas here they
move from right to left.
The MOV AX, BX instruction It is crucial to remember that a Also, note the flag register remains Figure below shows all possible
transfers the word contents of the MOV instruction always copies the unaffected by most data transfer variations of the data-addressing
source register (BX) into the source data into the destination. instructions. The source and modes using the MOV instruction.
destination register (AX). The source The MOV never actually picks up destination are often called This illustration helps to show how
never changes, but the destination the data and moves it. operands. each data-addressing mode is
always changes. formulated with the MOV
instruction and also serves as a
reference on data-addressing
modes.
• Register addressing: Register
addressing transfers a copy of
a byte or word from the
source register or contents of
a memory location to the
destination register or
memory location.
• Example: The MOV CX,
DX instruction copies the
word-sized contents of
register DX into register
CX.
• Immediate addressing:
Immediate addressing
transfers the source, an
immediate byte, word,
doubleword, or quadword of
data, into the destination
register or memory location.
• Example: The MOV AL,
22H instruction copies a
byte-sized 22H into
register AL
• Direct addressing: Direct
addressing moves a byte or
word between a memory
location and a register. The
instruction set does not
support a memory-to
memory transfer, except
with the MOVS instruction.
• Example: The MOV CX,
LIST instruction copies
the word-sized contents
of memory location LIST
into register CX.
• Register indirect addressing:
Register indirect addressing
transfers a byte or word
between a register and a
memory location addressed
by an index or base register.
The index and base registers
are BP, BX, DI, and SI.
• Example: The MOV AX,
[BX] instruction copies
the word-sized data from
the data segment offset
address indexed by BX
into register AX.
• Base-plus-index addressing: Base-
plus-index addressing transfers a
byte or word between a register
and the memory location
addressed by a base register (BP
or BX) plus an index register (DI or
SI).
• Example: The MOV [BX+DI],
CL instruction copies the
byte-sized contents of
register CL into the data
segment memory location
addressed by BX plus DI.
• Register relative addressing:
Register relative addressing
moves a byte or word between a
register and the memory location
addressed by an index or base
register plus a displacement.
• Example: MOV AX,[BX+4] or
MOV AX, ARRAY[BX].
• The first instruction loads AX
from the data segment
address formed by BX plus 4.
The second instruction loads
AX from the data segment
memory location in ARRAY
plus the contents of BX.
• Base relative-plus-index addressing
Base relative-plus-index addressing
transfers a byte or word between a
register and the memory location
addressed by a base and an index
register plus a displacement.
• Example: MOV AX,
ARRAY[BX+DI] or MOV AX,
[BX+DI+4].
• These instructions load AX
from a data segment memory
location. The first instruction
uses an address formed by
adding ARRAY, BX, and DI and
the second by adding BX, DI,
and 4.
Program Memory Addressing Modes

Program memory-addressing This section introduces these


modes, used with the JMP three addressing forms, using
(jump) and CALL instructions, the JMP instruction to
consist of three distinct forms: illustrate their operation.
• direct,
• relative,
• and indirect.
Direct program memory addressing is what
many early microprocessors used for all jumps
Direct and calls.
Program
Memory Direct program memory addressing is also
used in high-level languages, such as the GOTO
Addressing instruction.

The microprocessor uses this form of


addressing, but not as often as relative and
indirect program memory addressing are used.
The instructions for direct program memory Figure shows the direct intersegment JMP instruction
addressing store the address with the opcode. For and the 4 bytes required to store the address 10000H.
example, if a program jumps to memory location This JMP instruction loads CS with 1000H and IP with
10000H for the next instruction, the address (10000H) 0000H to jump to memory location 10000H for the next
instruction.
is stored following the opcode in the memory.

An intersegment jump is a jump to any memory location within the entire memory system.) The
direct jump is often called a far jump because it can jump to any memory location for the next
instruction.
Relative Program Memory Addressing

Relative program memory For example, if a JMP instruction


addressing is not available in all skips the next 2 bytes of memory,
early microprocessors, but it is the address in relation to the
available to this family of instruction pointer is a 2 that
microprocessors. The term adds to the instruction pointer.
relative means “relative to the This develops the address of the
instruction pointer (IP)”. next program instruction.
• An example of the relative JMP instruction is
shown below.

• Note that the JMP instruction is a 1-byte


instruction, with a 1-byte or a 2-byte
displacement that adds to the instruction
pointer. A 1-byte displacement is used in
short jumps, and a 2-byte displacement is
used with near jumps and calls. Both types
are considered to be intrasegment jumps.
• An intrasegment jump is a jump anywhere
within the current code segment.
Indirect Program
Memory Addressing
• The microprocessor allows
several forms of program
indirect memory addressing
for the JMP and CALL
instructions.
Stack Memory Addressing Modes

• The stack plays an important role in all microprocessors. It holds data


temporarily and stores the return addresses used by procedures. The stack
memory is an LIFO (last-in, first-out) memory, which describes the way that
data are stored and removed from the stack.
• Data are placed onto the stack with a PUSH instruction and removed with a
POP instruction.
• The CALL instruction also uses the stack to hold the return address for
procedures and a RET (return) instruction to remove the return address
from the stack.
• The stack memory is maintained by two registers: the stack
pointer (SP) and the stack segment register (SS). Whenever a
word of data is pushed onto the stack, the high-order 8 bits
are placed in the location addressed by SP – 1. The low-order 8
bits are placed in the location addressed by SP – 2. The SP is
then decremented by 2 so that the next word of data is stored
in the next available stack memory location.

• The SP register always points to an area of memory located


within the stack segment. The SP register adds to SS x 10h to
form the stack memory address in the real mode.
• Whenever data are popped from the stack, the low-order 8 bits are
removed from the location addressed by SP. The high-order 8 bits are
removed from the location addressed by SP+1. The SP register is then
incremented by 2.

• Note that PUSH and POP store or retrieve words of data—never


bytes—in the 8086 microprocessors.
• Data may be popped off the stack into any register or any
segment register except CS. The reason that data may not
be popped from the stack into CS is that this only changes
part of the address of the next instruction.
Example Swap operation using stack

mov ax, 1000h

mov bx, 2000h

push ax; 1000h to stack

push bx; 2000h to stack

pop ax; 2000h to ax

pop bx; 1000h to bx


Indexed Addressing with Displacement

Combines base register, Example: MOV AX, Useful in accessing Flexible for handling multi-
index register, and ARRAY[BX+DI+10] structured data such as dimensional data.
displacement. arrays and records.
Effective Address Calculation

THE EFFECTIVE ADDRESS (EA) IS EXAMPLE: EA = [BX] + [SI] + MICROPROCESSORS USE EA TO IMPORTANT FOR UNDERSTANDING
COMPUTED FROM REGISTERS + DISPLACEMENT. LOCATE DATA IN MEMORY. HOW INSTRUCTIONS MAP TO
DISPLACEMENT. PHYSICAL MEMORY.
Stack Operations in
Procedures

CALL pushes the return


address onto the stack.
RET pops the address back
and resumes execution.
Example sequence:
Differences Between Near and Far Calls

Far call: jump to a Far calls allow


Near call: jump within
different code modular programming
the same code Example:
segment (CS:IP across multiple
segment.
updated). segments.

Near: CALL
1234H (only IP
changes).

Far: CALL FAR


PTR PROC1 (both
CS and IP
change).
Practical Example:

Array Processing

Using addressing modes to process arrays.

Example:

MOV CX, 5 ; loop counter

MOV SI, OFFSET LIST

You might also like