Unit 13
Unit 13
ARCHITECTURE
Structure Page No.
13.0 Introduction
13.1 Objectives
13.2 Structure of 8086 CPU
13.2.1 Bus Interface Unit
13.2.2 Execution Unit
13.2.3 Register Set
13.3 Instruction Set of 8086
13.3.1 Data Transfer Instructions
13.3.2 Arithmetic Instructions
13.3.3 Bit Manipulation Instructions
13.3.4 Program Execution Transfer Instructions
13.3.5 String Instructions
13.3.6 Processor Control Instructions
13.4 Addressing Modes
13.4.1 Register Addressing Mode
13.4.2 Immediate Addressing Mode
13.4.3 Direct Addressing Mode
13.4.4 Indirect Addressing Mode
13.5 Summary
13.6 Solutions/Answers
13.0 INTRODUCTION
In the previous three blocks of this course, you have gone through the concept of data
representation, logic circuits, memory and I/O organisation, instruction set
architecture, micro-operations, control unit etc. of a computer system. The processor
of a general purpose computer consists of an instruction set, which uses a set of
addressing modes. The control unit of a processor uses a set of registers and arithmetic
logic unit to process these instructions. This unit present details of a micro-processor,
in the content of all the above concepts. We have selected a simple micro-processors
8086, for the discussion. Although the processor technology is old, all the concepts
are valid for higher end Intel processor family, which are commonly referred to as x86
family. This block does not attempt to make you an expert assembly programmer,
however, you will be able to write reasonably good assembly programs . This unit
discusses the 8086 microprocessor in some detail. This unit will introduce you to
block diagram of components of 8086 microprocessor. This is followed by discussion
on the register organization for this processor. Some useful instructions and
addressing modes of this processor are also discussed in this unit. Please note the
concepts discussed in this unit may be useful in writing good Assembly Programs.
13.1 OBJECTIVES
After going through this unit, you should be able to:
explain the role of various components of 8086 microprocessor;
illustrate the use of segmentation in 8086 microprocessor;
use some of the important instruction of 8086 microprocessor
illustrate the use of different types of addressing modes of 8086 microprocessor.
5
Assembly Language
Programming
13.2 STRUCTURE OF 8086 MICROPROCESSOR
A microprocessor contains one or more processing unit on a single chip. Today's
processors contain multiple processing cores in a single chip, therefore are called
multi-core processors. A computer system consists of a micro-processor, memory unit
and input/output interfaces, internal and external connection structure, such as buses;
and several input/output devices. The bus size of a processor is a very important
design parameter. For example, the address bus of a processor, generally, can
determine the size of the physical main memory. The data bus determines the size of
the data that can be transferred from the memory to the processor registers.
The size of address bus of 8086 micro-processor is 20 bits and data bus is 16 bits.
Thus, 8086 micro-processor has 220 = 1M Byte base memory. From this memory,
about 640 KB was part of base RAM and remaining was used as ROM.
8086 micro-processor was designed as a complex instruction set computer with the
basic objectives of supporting more instructions, addressing modes and more
throughput. Present day multi-core processors are far more powerful than 8086 micro-
processor, but objective of this block is to introduce some of the basic features of
micro-processor and assembly language programming. For the basic discussion this
processor is good example.
A microprocessor executes a sequence of machine instruction, which can be
represented as the following notional program:
These units can function independently, therefore, they can function as two stages
instruction pipeline. Components of these two units as shown in Figure 13.1 are
explained in the following sections.
This unit then reads or writes the information from the physical address as
computed above.
o If an instruction is fetched, it is stored in the instruction stream queue.
6
Microprocessor
o Data is fetched into a general purpose register. Architecture
o In case of writing the data value of a selected register is written into a
desired memory location or I/O port .
An instruction queue is useful only if more than one instructions are fetched
simultaneously, which may be used for instruction pipelining involving the stages of
instruction fetch and instruction execution.
The BIU of this microprocessor has four specific segment registers, namely CS: Code
Segment register, DS: Data Segment register, SS: Stack Segment register, and ES:
Extra Segment register. All of these registers are 16 bit long. Why segmentation?
Segmentation divides the 1 MB memory of the computer associated with this
microprocessor into logical overlapping segments of 64 KB. A program can have
several code, data and stack segments. However, a maximum of four segments, one
each of each type, may be available for accessing data and instructions at a specific 7
Assembly Language
Programming
time, as there are four segment registers only. Thus, a program can consist of logical
segments of code, data, stack etc. Thus, address of a data byte stored in the memory
consists of a double Segment Register (16 bits): Offset Register (16 bits) Pair. How
does this segmented addressing better than fetching two words? In the segmented
scheme an address included in an instructions consist of only the 16 bit memory
address, thus, a segment can be a maximum size of 216 = 64 KB only. In addition, as
the size of segment register is 16 bits, therefore, there can be 216 = 65536 number of
segments. Please note that these segments will be overlapping as the size of base
memory for this processor is only 1 MB. Figure 13.2 shows the memory organisation
of 8086 microprocessor. Thus, a segment register is loaded with the address of current
segments and offset is used to represent data within that segment. Thus, instruction
just needs to store 16 bit address only. The address adder computes the 20 bit physical
address from the Segment Register (16 bits): Offset Register (16 bits) Pair. Please note
all the content in Figure 13.2 is in hexadecimal notation.
Figure 13.2 shows two hypothetical segments (just for illustration) in the 1MB
memory using hexadecimal notation. Assume that one segment data is of 30 bytes,
thus it can be accommodated in the segment of size 32 Bytes. Please note that
segment start address for this segment is 0000h and offset of these locations are 0000
to 001Fh. Therefore, the second segment can start from the physical memory address
00020h. The second segment is assumed to be of 64 KB and starting from physical
memory 00020h. Therefore, it has segment starting address as 0002h and offset values
8
Microprocessor
from 0000h to FFFFh. An interesting fact about the memory of 8086 processor is that, Architecture
although a single byte has an address, but in a single memory access two bytes are
transferred though data bus. For example, access to an even memory offset 0000h will
transfer bytes at offset 0000h and 0001h. However, in case, you try to access an odd
memory offset like 0013h, then the bytes 0012h and 0013h would be transferred to the
processor.
Now, the question is given the segment starting address of 16 bits and segment offset
of 16 bits, how will you compute the physical address? The designers of 8086 used an
address adder to compute physical address. The addition is performed as follows:
Given: Segment Address 0002h; and offset say 0001h
Physical address is computed by shifting segment address to left by one
hexadecimal digit (appending 0 as the lowest hexadecimal digit and add the
offset in the result).
The Segment Address (hexadecimal) 0 0 0 2
Shift left and add zero in least significant digit 0 0 0 2 0
Add the offset 0 0 0 1
Resulting 20 bit physical address 0 0 0 2 1
Given: Segment Address 0002h; and offset say FFFFh. The physical address will be
computed as:
The Segment Address (hexadecimal) 0 0 0 2
Shift left and add zero in least significant digit 0 0 0 2 0
Add the offset F F F F
Resulting 20 bit physical address 1 0 0 1 F
Please note that F+2 will be 15+2=17, so addend is 1 and carry is 1. Also
when you add carry 1 to F, it will be 16, which is addend is 0 and carry is 1
(b) Stack Segment (SS) register and Stack Pointer (SP) register, which points to the
top of the stack in the stack segment, to compute the address of the top of the
stack. The following example explains their use.
An assumed Stack Segment(SS) Address (hexadecimal) F 1 1 D
Shift left and add zero in least significant digit F 1 1 D 0
Assume that SP contains an offset 0110h 0 1 1 0
9
Assembly Language
Programming
Resulting 20 bit physical address F 1 2 E 0
(c) Data Segment (DS) register and Offset to compute the address of the data to be
fetched. The following example explains their use.
An assumed Data Segment(DS) Address (hexadecimal) A 5 8 3
Shift left and add zero in least significant digit A 5 8 3 0
Assume that data offset is A021h A 0 2 1
Resulting 20 bit physical address A F 8 5 1
(d) Extra Segment (ES) register and offset to compute the address of extra data
segment (in case two data segments are used at the same time).
Control Circuitry for Instruction Decode and operand specification and ALU
The 8086 processor uses a micro-programmed control unit, which decodes the
instruction and executes it as per the micro-program stored in the control memory.
The control unit is also responsible for generating the control timing sequences. ALU
performs the operation on the data as instructed by the control unit.
Registers
8086 has several kinds of registers, which includes general purpose, special purpose
registers and a special flag register. The next section explains the role of different
registers of 8086 micro-processor.
13.3.3 Register Set
The 8086 registers have five different categories of registers. The following table
explains the role of these registers.
Register Category Register Name and Special Purpose, if any
Size
Segment Registers CS (16 bits) For storing the base address of
code segment
DS (16 bits) For storing the base address of
data segment
SS (16 bits) For storing the base address of
stack segment
ES (16 bits) For storing the base address of
extra data segment
General Purpose AX - 16 bits ; it It is also called accumulator
Register: Can be used for consists of two byte register. It can store the results of
any computation, in register AH, which addition or subtraction operation;
addition they are used for stores the higher byte for some instructions like
specific purpose as stated and AL, which stores multiplication and division it
in this table the lower byte store one of the operand.
BX - 16 bits ; it It is also called base register. It
consists of BH and stores the base location of a
BL memory array.
CX - 16 bits ; it It is also called counter register.
consists of CH and It can be used for keeping count
CL in looping instructions
10
Microprocessor
DX - 16 bits ; it This register can be used for I/O Architecture
consists of DH and operation.
DL
Pointer and Index BP (16 bits) Base Pointer register used in
Registers: These registers stack segment
can also be used as SI (16 bits) Source Index register used in
general purpose registers data segment
DI (16 bits) Destination Index register used
in extra data segment
Special Register SP Stack Pointer register, points to
the top of the stack.
Flags Register It consists of 16 flags Some of the important flags are
set by the last ALU carry flag (CF), Parity Flag (PF),
operations. Each flag Auxiliary Flag (AF), Zero flag
is 1 bit logn (ZF), Sign Flag (SF), Overflow
Flag (OF), Interrupt Enable flag
(IF) and other control flags.
The following are some of the important functional groups of the 8086 instructions.
12
Microprocessor
The maximum size of this stack segment is 0100h having offsets 0000h to Architecture
00FFh. The stack segment register value is not shown.
In 8086 microprocessor, the stack grows from higher offset to lower offset.
The stack would be empty if SP contains 0100h. Stack is full when SP is
0000h.
The PUSH instruction causes the decrementing the stack pointer by a value 2
(as stack is a word stack and the offset is an address of a byte), i.e. SP=SP-2,
and then the word operand of the PUSH instruction is put in the stack
locations pointed to by the SP.
POP instruction results in moving the content at the stack location into the
destination register, specified by the instruction. This is followed by
incrementing the stack pointer register value by 2, i.e. SP=SP+2.
PUSHF and POPF instructions: The PUSHF instruction is used for pushing the
current flags register on to the stack, while POPF pops the content at the top of the
stack to fags register.
Other data transfer instructions
There are a number of other data transfer instructions. These instruction and their
purpose is given in the following table:
MNEMONIC DESCRIPTION
XCHG Exchanges bytes of words of source and destination. At least
destination, source one operand should be a register operand.
XLAT This is a complex instruction, which translates a byte of AL
register using a lookup table. This instruction uses AL register
as the operand. An example of this instruction is given in Unit
15.
LEA register, This instruction results in loading of 16 bit effective address of
source source operand to the specified register operand. This
instruction is useful for array index manipulation.
IN accumulator, This instruction is used to transfers a byte or word from a
port address specified Input port to accumulator register. The instruction can
use DX register as implied operand for port address. The port
address can also be an immediate operand.
This instruction can be used to transfer a byte or word, which is
OUT port address, in accumulator register to specified output port address of an
Accumulator output devices, such as monitor or printer
LDS/LES These instructions and used to loading data segment/extras data
segment respectively along with one specified registers. Details
on these instructions are beyond the scope of this unit.
LAHF/SAHF The LAHF loads the low byte of flags register to AH register,
while SAHF stores value of AH register to low byte of flags
register.
Example:
Consider the AL register has ASCII digit '7' and BL contains ASCII '6'. You want to
add these two values to get an answer 13 in decimal. One of the way would be to
convert these operand into binary and perform the addition and convert the results
back to desired format. Other way will be to use AAA as follows:
MUL, DIV and IDIV instructions: MUL source, DIV source and IDIV source
MUL and DIV instructions are unsigned multiplication and unsigned division
instructions respectively. IDIV is a signed division instruction. The source can be a
memory or register operand, which contains either byte data or word data. For these
instructions one of the operand is assumed to be AL register (if data is of byte type) or
AX register (if data is of word type). The result of MUL instruction is stored in AX
register (if data is of one byte) or DX and AX pair (if data is of word type). Thus,
symbolically the MUL instructions can be represented as:
AX AL × source (if source is 8 bit data)
DX, AX AX, sources (if source is 16 bit data)
In case in this instruction, if most significant bit of the result is 0, then carry and
overflow flags are set to 0. In case a byte is to be multiplied with a word operand, then
you must first convert the byte operand to a word operand using instructions like
CBW given later in the unit.
The result of DIV and IDIV instructions for byte operands is stored as AH stores
remainder and AL stores quotient of division, or for word operands DX stores the
remainder and AX stores the quotient. in AH register (if data is of one byte) or DX
and AX pair (if data is of word type). Thus, symbolically the MUL instructions can be
represented as:
AH (Remainder) AL (Quotient) AL / source (if source is 8 bit data)
DX (Remainder) AX (Quotient) AX / source (if source is 16 bit data)
In the division operation a 0 value in the source register will result in run time error.
Example:
Assume that AL register contains 11h and BL register contains 02h.
Multiplication and division instructions will give following results:
MUL BL ; Result 11h × 02h = 22h; The AH = 00h and AL=22h
DIV BL ; Result 11h / 02h = Remainder in AH= 01h and
; Quotient in AL 08h
CMP instructions: compares destination and source operands
This is a very interesting instruction used for comparing two operands. This
instruction only sets the flag by subtracting source from the destination operand (both
byte or both word). Both the source and destination operands cannot be memory
operands at the same time. This operation may set carry flag zero flag, sign flag etc.
The following example explains how flags may be set by this operand. This
instruction only changes the flags, no operand value is changed.
Example:
Instruction Flags if AX= CX Flags if AX > CX Flags if AX < CX
CMP AX, CX CF=0; ZF=1; SF=0 CF=0; ZF=0; SF=0 CF=1; ZF=0; SF=1
Other arithmetic instructions
Some of the other instructions are given below:
SUB This instruction subtract source from destination. The carry flag in
destination, subtraction is a borrow flag.
source
SUB Subtracts with previous borrow, if any.
destination,
source
NEG source Creates the 2's complement of source number.
15
Assembly Language
Programming AAS, DAS Works in a similar manner as AAA and DAA, except they operate
after subtraction operation.
AAM, AAD Works in a similar manner as AAA, except the operation is
multiplication and division respectively.
CBW, CWD These instructions convert byte to word or word to double word
respectively. The value of sign bit is filled in the upper byte or word
as the case may be. For CBW operand is in AL register and resulting
word is in AX register; whereas for CWD the operand is in AX
register and the double word is in DX, AX pair.
All the bits of the byte are shifted towards the right. The most significant bit gets the
value 0 and least significant bit is pushed to the carry flag (shown in green colour).
In the arithmetic shift right, all the bits are shifted towards the right. The most
significant bit, which is a sign bit retains the same sign (please see the 1’s in the left
most position in the diagram above) and least significant bit is pushed to the carry flag
(shown in green colour).
In the Rotate shift left, all the bits are shifted towards the left. The most significant bit
is shifted to CF as well as rotated to least significant bit, as shown above (in green
colour).
.
CF AL Register Value ROR is rotate right;
0 1 0 0 0 0 0 1 1 Initial Value
1 1 1 0 0 0 0 0 1 After execution of ROR AL
Direction of shift
In the Rotate shift right, all the bits are shifted towards the right. The least significant
bit is shifted to CF as well as rotated to most significant bit, as shown above (in green
colour).
CF AL Register Value RCL is rotate left with carry;
0 1 0 0 0 0 0 1 1 Initial Value
1 0 0 0 0 0 1 1 0 After execution of RCL AL
Direction of shift
In the Rotate shift left with carry, all the bits are shifted towards the left. The most
significant bit is shifted to CF, and the CF is rotated to the least significant bit (shown
in blue colour)
CF AL Register Value RCR is rotate right with carry;
0 1 0 0 0 0 0 1 1 Initial Value
1 0 1 0 0 0 0 0 1 After execution of RCR AL
Direction of shift
In the Rotate shift right with carry, all the bits are shifted towards the right. The least
significant bit is rotated to CF (shown in blue colour), and the CF is shifted to the
most significant bit.
Call and return instructions are used form calling a procedure and once execution of
the execution of the procedure is over RET instruction brings the control to the next
instruction after the CALL instruction. In 8086 microprocessor there are two types of
calls, viz. NEAR call and FAR call. The near call is within the same segment, whereas
FAR call is to a different segment. A call instruction has the following basic format:
CALL <address of procedure>
Now, the question is how to recognize, if it is a NEAR or FAR procedure call? This is
resolved by the assembler from the declaration of the procedure, which is created as a
NEAR or FAR procedure. An example, explaining this is discussed in Unit 15 of this
Block. A call to the procedure can be made using the CALL instruction. For example,
if the name of a procedure in a separate code segment is procdeure1, then the
following call instruction will be used:
CALL procedure1 ;
This instruction will cause the execution for following sequence of operations:
1. If, it is a FAR procedure, then, present CS and IP should be saved as return
address on the top of the stack, otherwise only IP will be stored on the stack.
SP=SP-2; SS[SP]CS; // This step will not be required in NEAR procedure
SP=SP-2; SS[SP]IP;
2. The CS will be loaded with the code segment address of procedure1 and IP
will be loaded with the offset of procedure1.
CS= CS of procedure1; // This step will not be required in NEAR procedure
IP = Offset of first instruction of procedure1;
3. The next instruction as per CS:IP value updated in step 2 will be executed
next.
A procedure ends in a return instruction (RET). It causes the called procedure to
return to the calling program. The following sequence of actions are performed by the
RET instruction.
1. Perform the following actions:.
18
Microprocessor
CS SS[SP] ; SP=SP+2;; // NOT performed in NEAR procedure Architecture
IP SS[SP] ; SP=SP+2;
2. The next instruction as per CS:IP value updated in step 1 will be executed
next.
Jump instructions:
8086 micro-processor have instructions for unconditional and conditional jump
instructions. The unconditional jump can be to NEAR or FAR label. It only requires
one operand, which is the address, specified using a Label, of the next instruction to
be executed. The format of this instruction is given below:
JMP Label
Loop instructions:
A loop instruction (LOOP label) uses CX register as a counter register. The label in
the loop instcution should be in the range -128 to +127. Prior to a loop instruction, the
looping count value should be moved to CX register. The Loop instruction decrements
the CX register and checks if CX register has zero value. If CX is not zero, then loop
instruction takes the program back to the instruction, which is specified by the label of
that instruction. In case, CX is zero then the loop is terminated, i.e., the next
instruction after the loop instruction is executed in sequence. 8086 micro-processor
has a number of loop instruction, which differ in condition the condition of loop
termination. The following table lists some of these instructions, which may be used
19
Assembly Language
Programming
later Units. There are many other such instructions for looping, a discussion on them
is beyond the scope of this unit.
Example: Let us assume you have byte array of 40h bytes. Write an assembly program
segment that check if each of these elements have a value 00F0h.
Solution: Please note the two conditions - the first condition is that each element
should be equal to 00F0h and the second condition is loop is to be executed 40h times.
Thus, LOOPE instruction would be used, but prior to that you need to set different
registers. The program segment for looping is shown below:
; Assume that the name of the array is BYTECOST
MOV BX, OFFSET BYTECOST ; This instruction will cause the BX register to
; point at the first element of byte array BYTECOST.
DEC BX ; Decrementing the value of BX register by one.
; This will cause BX to point to one byte prior to
; BYTECOST array. Why is this instruction?
; This is due to specific loop instructions below.
MOV CX,40h ; Initialise the loop counter to size of array
L1: INC BX ; Move to the next element in the array.
CMP [BX],0F0h ; Compare the array element to 0F0h
LOOPE L1 ; Loop if the present array element is equal to
; 0F0h as per CMP instruction and CX is not zero.
It may be noted that LOOPE instruction will automatically decrement the value of the
counter CX register.
In addition to the program execution control transfer, there are string instructions
which are useful for string matching. Such instructions were specially designed for
8086 microprocessor, so that it can perform faster string comparisons. Some of these
instructions are discussed in the next section.
20
Microprocessor
This instruction moves data from one byte string to another byte string. This string Architecture
operator uses several registers implicitly. The source string is assumed to be in data
segment, indexed by SI register, whereas the destination string is assumed to be extra
data segment indexed by DI register. CX is used as counter register. On transfer of
one byte data from sources string to destination, automatically results in increment of
SI and DI registers, and decrement of CX register.
Example: Assume that both data segment and extra data segment registers start from
segment address 00FFh and a byte string of length 0100h starting at an offset 0400h is
to be coped at an offset 0600h. Write the program segment to show this transfer.
; Assuming data segment and extra data segments registered are already initialised.
Instruction Purpose
CMPS/CMPSB/ This instruction compares two byte or word strings, use of CX, SI
CMPSW and DI remains the same as MOVS. It is recommended to use
REPE in this case.
SCAS/SCASB/ This instruction compares a string with a value in AL or AX
SCASW register for a byte or word string respectively. The string to be
scanned is assumed to be in extra data segment. This instruction
uses CX and DI registers, when REP prefix is used.
LODS/LODSB/ This instruction is used to load a byte or word of a string pointed to
LODSW by SI register into AL or AX registers respectively.
STOS/STOSB/ This instruction is used to store a byte of word from AL or AX
STOSW registers respectively into a location pointed by DI register.
Instruction Purpose
STC This instruction sets the carry flag.
CLC This instruction clears the carry flag.
CMC This instruction complements or inverts the state of the carry flag.
STD This instruction sets the direction flag (DF=1), so the SI and DI are
decremented automatically.
CLD This instruction clears the direction flag (DF=0), so the SI and DI are
incremented automatically.
There are many other process control instructions. You may refer to further readings
to know more about these instructions.
22
Microprocessor
Architecture
BX register contains the offset of the location in Data Segment, whereeas BP register
points to the base of the stack segment register. The index registers SI and DI also
contains offset in the Data Segment and Extra data Segment respectively.
These registers can be combined to create several indirect addressing modes. These
are:
Register indirect: In this addressing mode the register contains the address of the data.
In general, the type of register as stated above determines the segment in which the
data is to be accessed. Examples of this mode are:
MOV AL, [DI] ; Move the byte at the memory location ES:DI to AL.
MOV AL, [BX] ; Move the byte at the memory location DS:BX to AL.
Based indirect: In this addressing mode a base register and a displacement are added
to compute the offset of address of data in the related segment. Example of this mode
are:
MOV AL, [BX+2] ; Move the byte at the memory location DS:BX+2 to AL.
Indexed indirect: In this addressing mode an index register and a displacement are
added to compute the offset of address of data in the related segment. Example of this
mode are:
MOV AL, [DI+2] ; Move the byte at the memory location ES:DI+2 to AL.
There are two more such indirect addressing modes, viz. Based Indexed and Based
Indexed with displacement, however, they are rarely used and are not explained in this
Unit.
13.6 SUMMARY
23
Assembly Language
Programming
In this unit, you have gone through the basic architecture of 8086 microprocessor.
This architecture was a creative design and used many interesting concepts related to
enhancing the speed of instruction processing. First of these is the concept of use of
segment registers to reduce 20 bit physical address to a 16 bit offset address, reducing
the size of instruction using direct addressing, second faster string processing by
using two separate segments to speed up string operations such as matching, third use
of pipelining by designing two sections in CPU, fourth use of instruction queue for
pre-fetching instructions and so on. 8086 assembly language forms the basis of Intel
instruction sets of advanced processors and may help you appreciate the assembly
language of those processors.
Some of the key features of this processor include:
It has 20 bit address bus, therefore, base memory is 1 MB
It has 16 bit data bus, thus can fetch two bytes simultaneously
It has four segment rgisters that along with other pointer registers converts 16
bit offsets to 20 bit physical address.
It has large number of instructions of different types, which allows writing of
powerful assembly programs.
Please refer to the further reading for more details on 8086 assembly language
programming.
13.7 SOLUTIONS/ANSWERS
(b)
DS (in hexadecimal) 0 2 1 1
Shift left by one Hexadecimal digit 0 2 1 1 0
BX (in hexadecimal) 0 1 0 0
Physical address (Hexadecimal) 0 2 2 1 0
(c)
SS (in hexadecimal) 4 2 A A
Shift left by one Hexadecimal digit 4 2 A A 0
SP (in hexadecimal) 0 1 2 3
Physical address (Hexadecimal) 4 2 B C 3
24
Microprocessor
3. Flag register is used to store all the flag bits, which are generated as a result of Architecture
last instruction. Some of these flags are sign flag, carry flag, overflow flag etc.
Flag register cannot be used as a general purpose register.
2. SHL is shift left instruction and identical to arithmetic shift left instruction.
Compare the different types of shift instructions of 8086 micro-processor.
However, SHR and SAL differ and different input is added to the left most bit.
Rotate instruction ROL and ROR just rotates the word/byte, whereas RCL and
RCR also rotate the sign bit. (Please refer to section 13.4.3).
3. Perform test instruction on the operands (please make sure both the operands are
not memory operand). If it sets the zero flag, then both the operands are same;
otherwise they are different.
1. CALL statement calls a subroutine, i.e. the next instruction to be executed by the
processor should be the first instruction of the subroutine. Since on completion of
the subroutine execution the next instruction of the calling program is to execute
therefore the return address is stored by the CALL instruction. RET instruction
just brings the control back the the next instruction after CALL instruction in the
calling program.
2. There are primarily two types of jump instructions: unconditional jump and
conditional jumps. The unconditional jump instruction causes a compulsory jump
to specified label. There are a number of conditional jump instructions, where a
jump is taken if the related condition is fulfilled; else next instruction in sequence
is executed.
3. Loop instruction in each iteration decrements CX register, and checks the value of
CX. In case it is not zero, you go back to the Label from where the loop started.
However, if the CX register is zero, the next instruction in sequence is executed.
4. String instructions in 8086 microprocessor are specially designed for efficient
execution of string operations. For example, to match two strings, one string each
be put in DS and ES with DS:SI pointing to first string and ES:DI pointing to
second string. String length is put in CX register. The string matching instruction
on using REPE command will compare the first byte and will increment SI and
DI; and decrement CX. Thus, you do not need to write lengthy program for string
matching, which includes all the operation as given above.
5. Immediate Operand
MOV AL, (9+7)*2 ; move 32 to AL register.
Register Addressing
MOV AL, DL ; move DL to AL register.
Direct Addressing
MOV AL, X ; move content of byte location X to AL register.
Register Addressing
MOV AH, [BX] ; move content of location, whose address is
; DS:BX to AL register.
25