Lecture 12
Lecture 12
Lecture 12
• PUSH source
POP destination
•
CS is not a valid destination for POP
• Example Instructions
PUSH BX
PUSH [BX]
PUSH DS
PUSH COSTP
POP CX
POP [SI]
• The highest offset address is in SP register, i.e, SP will contain the offset of the highest address
with respect to the base address.
• For example, if the stack is defined from addresses 20000H to 203E8H, SS = 2000H and SP =
03E8H, this stack then has a size of 3E8H bytes (1000 bytes).
• In the 8086, only a word (16 bits) can be pushed on to stack. A push thus causes two memory
locations to be accessed.
Operation of the Stack
Defining a Stack
• We have to define elements including the stack size, base address of segment and the
stack top.
• If we are using the tiny model, this is done by DOS – but in other memory models, we
will have to do it ourselves.
• .MODEL SMALL
.STACK 400H
.CODE
.STARTUP
.EXIT
END
Instructions to enter through keyboard and display on
the screen
Addressing Modes
• The way in which operands are specified in an assembly language
instruction is called its addressing mode.
• We will use the MOV instruction for understanding these modes. This
has the format:
MOV destination, source
Addressing Modes
• The basic assumptions in this context are:
• the operands can be in registers, in memory, or may be in the
instruction itself. However the 8086 does not have an addressing
mode in which both operands are in memory locations
• In the case of two operands, one of them can be in memory, but the
other will have to be placed in a register
• Data types should match – i.e., the source and destination should
both be either bytes or words.
Addressing Modes
• Register Addressing
Here both the source and destination are registers. No memory access is involved.
MOV AL, AH
• Immediate Addressing
In this mode, the source will be a constant data
MOV AL, 45H
MOV PRICE, 40
• Direct Addressing
Here either the source or the destination will be a memory address.
MOV AX, [2345H]
MOV [1089H], AL
MOV AX, PRICE
MOV COST, AL
Addressing Modes
• Note that BP cannot be used without a displacement. See it being used in ‘register relative’ mode
but not in register indirect mode.
Segment Override
• The 8086 has a set of instructions for handling blocks of data in the form of
bytes or words.
• They are called ‘string’ instructions. A string is an array of data of the same
type – for example, a character string or a byte string.
• String instructions can be seen to be useful when in the memory, data has to
be moved, searched or compared in blocks (arrays).
Pre-requisites for using String Instructions
• Two segments are to be defined i.e., the data segment and the extra
segment. This means that the corresponding segment registers DS and ES
have to be initialized and used. The data segment is the source segment
and the extra segment is the destination segment.
• The direct call is like a direct jump instruction, and is three bytes long.
• It is relative and the destination can be -32,768 bytes to +32,767 bytes from the address of the
instruction following the call.
• Indirect Call
• For a far call, four bytes are needed to specify a destination. But a register cannot
specify it.
• Therefore, the four bytes needed to specify a destination are stored in memory and
pointed by a register.
• As an example CALL DWORD PTR [SI] can be a far call instruction. [SI] and [SI + 1] gives
the new value of IP and [SI + 2] and [SI + 3] gives the new
value of CS.