0% found this document useful (0 votes)
32 views

Lesson 2

The document discusses basic PC addressing schemes. It explains that 16-bit addresses are relative to a base address, allowing access to more than 64KB of memory. Addresses have two parts: a segment address and offset. The effective address is the segment address plus offset. This scheme allows addressing up to 1MB of memory using segments and segment registers. The document also describes stack implementation and different addressing modes like direct, indirect, and indexing addresses.

Uploaded by

Jesus Grado
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Lesson 2

The document discusses basic PC addressing schemes. It explains that 16-bit addresses are relative to a base address, allowing access to more than 64KB of memory. Addresses have two parts: a segment address and offset. The effective address is the segment address plus offset. This scheme allows addressing up to 1MB of memory using segments and segment registers. The document also describes stack implementation and different addressing modes like direct, indirect, and indexing addresses.

Uploaded by

Jesus Grado
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 26

EE 193

Addressing
Addressing
• Addressing refers to the process of
specifying the location of an object to will
access
Basic PC Addressing Scheme
• Instructions work with addresses that are
16-bit long
• The possible addresses run from 0000H to
FFFFH
• Thus, using straightforward scheme, the
processor would only be able to address up to
64k bytes of memory
• 64k is not much memory

• Intel 86 processors use a different scheme to


address this problem
Basic PC Addressing Scheme
• 86 Intel processors consider the 16-bit address
to be relative to a base address
• By moving the base address, the processor is
able to access different 64k of memory
• Within a program, addresses consists of two
parts: segment address and an offset
• Segment address is a 20-bit address that
corresponds to the base address
• Offset address is a 16-bit address that is used
to access locations relative to base address
Basic PC Addressing Scheme
•The actual address is called the effective
address
Effective address = segment address + offset address

• Example: 562A3H = 5000H + 62A3H


Basic PC Addressing Scheme
•The actual address is called the effective
address
Effective address = segment address + offset address

• Example: 562A3H = 5000H + 62A3H


• Using this scheme, the processor can access

up to 100000H bytes of memory (1024 kbytes or


1 Mbytes)
Segments and Segments Registers
• To implement the addressing scheme, the
processor requires that all programs be divided into
segments.
• Segment - an area of memory that is up to 64kb

• Large programs must be partitioned into


segments
• Segment address are kept in segment registers:
CS, DS, ES, and SS
• Only four segments can be active at a time
• code segment, data segment, extra segment and
sack segment
Segments and Segments Registers
• The code segment contains the actual machine
instructions (sometimes called “code”)
• The stack segment holds the stack

• The data segment is the part of your program


that contains the data
• The extra segment can also be used to hold data

• All programs must have at least a code segment


and a stack segment
• Most program use at least a data segment
How segment registers are used
• In a program, you write an address by specifying
the two parts separated by a colon
• For example, if you want to refer to information in
the data segment with an offset of 6AH, you would
write the address as DS:6AH
How the stack is implemented
• Stack segment (SS) register always contains the
segment address of the stack
• The stack pointer (SP) register contains an offset
that points to the top of the stack
• The stack is organized as a list of 16-bit (2 bytes)
entries.
• The SS register points to the lowest address in
the list. The first PUSH places data in the entry
with highest address, next PUSH places data in
next highest address, and so on. At all times , the
SP points to the last data hat was pushed
How the stack is implemented
• Stack segment (SS) register always contains the
segment address of the stack
• The stack pointer (SP) register contains an offset
that points to the top of the stack
• The stack is organized as a list of 16-bit (2 bytes)
entries.
• The SS register points to the lowest address in
the list (or base of the stack)
• The satck starts from the highest address and
grows “down” toward its base
How the stack is implemented
• Example, SS holds 10000H and SP initially holds 0200H

PUSH data 1 PUSH data 2 PUSH data 3

101FFH 101FFH 101FFH


data 1 data 1 data 1
SP -- 101FEH 101FEH 101FEH
101FDH 101FDH 101FDH
data 2 data 2
101FCH SP -- 101FCH 101FCH
101FBH 101FBH 101FBH
data 3
101FAH 101FAH SP -- 101FAH

SS -- 10000H SS -- 10000H SS -- 10000H


How the stack is implemented
• When item is pushed,
• SP is decremented by 2 in order to point to the next
free location
• The item to be pushed is copied to the offset specified
by SP
• When item is popped,
• The item that SP points is copied to the appropriate
location
• SP is incremented by 2 in order to point to the
previous entry on the stack
Direct Addressing
• Direct addressing – addressing in which offset is
specified directly
• Example, to specify the location in the data
segment that has an offset of 10AH, you would
write DS:10AH
• Normally, we do not refer to items by using their
numeric offsets. Instead, we use names that
represent these items (called data items, read this)
• Example, if we use SUM to represent the offset
10AH, then using direct addressing, we write
DS:SUM to access the item
Direct Addressing
• You can also omit the DS term in DS:SUM.
When this is used, the assembler assumes that
you are specifying an item in data segment.
• However, if SUM is in extra segment, you need to
specify ES. That is, ES:SUM
Indirect Addressing
• Indirect addressing – addressing in which the offset
is specified as being the value of a register
• To reference a location with offset in a register you
specify the name of the register enclosed in square
brackets
• Example if SI register contains 1000H, then DS:[SI]
points to the data in DS with offset 1000H
• Any of the SP, BP, BX, SI, and DI registers may be
used for indirect addressing
Indirect Addressing
• Most of the time, it is not necessary to specify a
segment register because the processor will assume
one
• If SP or BP is used, the processor assumes that the
offset refers to the stack segment and uses SS
register. If BX, SI, and DI is used, the processor
assumes that offset refers to the data segment and
uses DS
• To override default, specify the segment register.
Example, ES:[BX] points to the data in extra
segment with offset in register BX
Indirect Addressing
• Summary of implied Segment Register Usage for
Indirect Addressing

Register Implied Segment Register


[SP] SS
[BP] SS
[BX] DS
[SI] DS
[DI] DS (ES with string instructions)
Indexing
• Indexing allows us to reference items relative to a
fixed location. This fixed location is called the base
address
•For instance, consider an array of 100 elements
that exists in the data segment as 100 consecutive
bytes. We may use the name LIST to refer to this
array
•The first element in array is accessed by specifying
LIST. The succeeding elements may accessed by
LIST+1, LIST+2, LIST+3, etc..
•The number that we add to a base address is caled
displacement
Index Registers
• Sometimes it is more useful to store the
displacement in a register. The different elements may
be accessed by simply changing the contents of the
register
• The SI and DI registers are used for this purpose
and are sometimes referred to as the index registers
• For example, if we use SI to store the displacement
for the array LIST,
LIST[SI]
• When the data structure contains words,
doublewords or quadwords, make sure you set the
index registers accordingly
Base Registers: The BX register
• You can also use registers to store base addresses
when indexing. BX is used for this purpose in data
segment; BP is used within the stack
• For example, we can place LIST in BX and use DI to
store the displacement. We can use
[BX][DI]
• For more complicated data structures, the assembler
allows us to use a name example, if we use SI to store
the displacement for the, a base address, and a
displacement. For example:
ARRAY[BX][SI]
General Rules for Specifying an Address
• When you specify a direct address, you use the
name of a data item and an optional base register,
index register, and a constant displacement.
Examples:
TABLE
TABLE [SI]
TABLE [DI] + 8
TABLE [BX] [SI] + 8

General Rules for Specifying an Address
• You can use SP, BP, BX, SI, or DI for indirect
addressing. With BP or BX, you can use SI or DI to
index. With all indirect addressing you can use
displacement.
[BP]
[SI]
[BX] [DI]
[SI] + 4
[BP] [DI] + 4
General Rules for Specifying an Address
• Within one address, direct or indirect, you cannot
use more than one base register nor more than one
index register.
• Rules for indexing:
• The index values can be in any order
• Register names must be in square brackets

• You can combine register names and a aconstant


displacement into one set of square brackets if you separate
the values +
• If you put the constant displacement in front of a register
name, you do not need to use a +
General Rules for Specifying an Address
• Examples,
TABLE [BX] [SI]+8
TABLE [BX+SI+8] Direct
addressing
TABLE [8+SI+BX]
[BP] [SI] + 12
12 [BP] [SI] Indirect
addressing
12 [BP + SI]
General Rules for Specifying an Address
• Recommended:
• Indexing with direct address

name [base] [index] + constant

• Indexing with indirect addressing

[base] [index] + constant

You might also like