Bcs-12 Unit-1
Bcs-12 Unit-1
ARCHITECTURE
Structure Page No.
Introduction
Objectives
Microcomputer Architecture
Structure of 8086 CPU
1.3.1 The Bus Interface Unit
1.3.2 Execut~onUnit (EU)
Register Set of 8086
Instruction Set of 8086
1.5.1 Data Transfer Instructions
1S.2 Arithmetic Instructions
1 S.3 Bit Manipulation Instructions
1 S.4 Program Execution Transfer Instructions
1 S.5 String Instructions .
1.5.6 Processor Control lnsthctions
Addressing Modes
1.6.1 Reg~sterAddressing Mode
1.6 2 Immediate Addressing Modc
1.6.3 Direct Addressing Modc
1.6.4 Indirect Address~ngMode
Summary
Solutions/Answers
1.O INTRODUCTION
In the previous blocks of this course, we have discussed concepts relating to CPU
organization, register set. ~nstructionset, addressing modes with a few examples. Let
us look at one micropmccssor architecture in regard of all the above concepts. We
have selected one of the sl~nplestprocessors 8086, for this purpose. Although the
131-ocessortechnology is old, all the concepts are valid for higher end Intel processor.
'Therefore, in this unit. w will discuss the 8086 microprocessor in some detail.
1.l OBJECTIVES
Input Device
Data bus .
Control Control Memory 1
I10 Ports CPU a
Output Device
Address bus
Figure 1: Components of a Microcomputer
Bus Sizes I
1. The Address bus: 8085 microprocessor has 16 bit lines. Thus, it can access up to
216 = 64K Bytes. The address bus of 8086 microprocessor has a 20 bits address
bps. Thus it can access upto 2" = 1M Byte size of RAM directly.
2. Data bus is the number of bits that can be transferred simultaneousli It is 16 bits
in 8086.
I Microprocessors
! The microprocessor is a complete CPU on a single chip. The main advantages of the
microprocessor are:
compact but powerll;
oan be microprogrammed for user's needs;
easily programmable and maintainable due to small size; and
useful in distributed applications.
c v
~
-
- Microprocessor
The assembly language for more advanced chips subsumes the simplest 8086/ 8088 Architecture
asselnbly language. Therefore, we will confine our discussions to Intel 8086/8088
asse~nblylanguage. You must refer to the further readings for more details on
asselnbly language of Pentium, G4 and other processors.
while (1)
F -
t Tht: 8086 microprocessor consists of two independent units:
1. The Bus Interface unit, and
a
I 2. The Execution unit.
Please refer to Figure 2 . .
8086 Address and Data Bus
8
I
8
a
8
8
8
a
I
a
I
8'
...*-......*.-..,
8
8
8
8
..--
......
8
a
*
J .-
.-% *
- .
Assembly Language
Programming
The word independent implies that these two units can function parallel to each other.
In other words they may be considered as two stages of the instruction pipeline.
The BIU (Bus Interface Unit) primarily interacts with the system bus. It performs
almost all the activities relating to fetch cycle such as:
Calculating the physical address of the next instruction
Fetching the instruction
Reading or writing data memory or 110 port from memory or Input1 Output.
1
The instruction1data is then passed to the execution unit. This BIU consists of
lI
(a) The Instruction Queue
The instruction queue is used to store the instruction "bytes" fetched. Please
note two points here: that it is (1) A Byte (2) Queue. This is used to store
information in byte form, with the underlying queue data structure. The
advantage of this queue would only be if the next expected instructions are
fetched in advance, thus, allowing a pipeline of fetch and execute cycles.
These are very important registers of the CPU. Why? We will answer this later.
In 8086 microprocessor, the memory is a byte organized, that is a memory
address is byte address. However, the number of bits fetched is 16 at a time. The
segment registers are used to calculate the address of memory location along
with other registers. A segment register is 16 bits long.
The BIU contains four sixteen-bit registers, viz., the CS: Code Segment, the DS:
Data Segment, the SS: Stack Segment, and the ES: Extra Segment. But what is
the need of the segments: Segments logically divide a program into logical
entities of Code, Data and Stack each having a specific size of 64 K. The
segment register holds the upper 16 bits of the starting address of a logical
group of memory, called the segment. But what are the advantages of using
segments? The main advantages of using segments are:
-
- Offss(t = 001Oh in stack segment
60000h
i 448AOh -
- Code segment base CS = 448Ah
64K
-
-
Offset = OO2Oh in data segment
300qOh --L
Although the size of each segment can be 64K, as they are overlapping segments we
can create variable sizeof'segments, with maximum as 64K. Each segment has a
specific function. 8086 supports the following segments:
As per model of assembly program, it can have more than one of any type of
segments. However,.at a time only four segments one of each type, can be active.
Assembly Language
Programming
range from OOOOh to FFFFh. But, how will the segment address and offset be added to
calculate physical address? Let us explain using the following examples:
Example 1 (In the Figure above)
The value of the stack segment register (SS) = 6000h
The value of the stack pointer (SP) which is Offset = 0010h
-Implied zero
6 0 0 1 0
Physical Address
Example 2
The offset of the data byte = 0020h
The value of the data segment register (DS) = 3000h
Physical address of the data byte
DS
- -
- Implied Zero
Offset
Physical Address
3 0 0 2 0
Example 3
The value of the Instruction Pointer, holding address of the instruction = 1234h
The value of the code segment register (CS) = 448Ah
Physical address of the instruction
Physical Address 4 5 A 0 4
Execution unit performs all the ALU operations. The execution unit of 8086 is of 16
bits. It also contains the control unit, which instructs bus interface unit about which
memory location to access, and what to do with the data. Control unit also performs
decoding and execution of the instructions. The EU consists of the following:
(b) Registers
All CPUs have a defined number of opera' :anal registers. 8086 has several general
purpose and special purpose registers. We ill discuss these registers in the following
sections.
,4X register is also known as accumulator. Some of the instructions like divide, rotate,
shift etc. require one of the operands to be available in the accumulator. Thus, in such
~nstructions,the value of AX should be suitably set prior to the instruction.
rn BX register is mainly used as a base register. It contains the starting base location of a
memory region within a data segment.
You will experience their usage in various assembly programs discussed later.
Segment Registers
Segment Registers are used for calculating the physical address of the instruction or
memory. Segment registers cannot be used as byte registers.
Flags Register
A flag represents a condition code that is 0 or 1. Thus, it can be represented using a 1
flip- flop. 8086 employs a 16-bit flag register containing nine flags. The following
table shows the flags of 8086.
Conditional flags are set by some condition generated as a result of the last
-- CF
PF
Carry Flag
Parity Flag
1 if there 1s a carry bit
1 on evenparity 0 on odd parity
Auxiliary F& -- Set (1) if auxiliary cany for BCD occurs
Set ~fresult is equal to zero
Indicates the sign of the result (1 for minus, 0
1. What is the purpose of the queue in the bus interface unit of 8086
. microprocessors?
................................................................................................
................................................................................................
................................................................................................
2. Find out the physicil addresses for the following segment register: offset
(a) SS:SP = 0100h:0020h
(b) DS:BX = 0200h:0100h
(c) CS:IP = 4200h:0123h
i
Microprocessor
(c) The Source Index (SI) and Destination Index(D1) registeis in 8086 can also be Architecture
used as general registers.
(d) -
Trag Flag (TR) is a conditional flag.
-
1.5 INSTRUCTION SET OF 8086
-
Afler discussing the basic organization of the 8086 micro-processor, let us now
provide an overview of various instructions available in the 8086 microprocessor. The
instruction set is presented in the tabular form. An assembly language instruction in
the 8086 includes the following:
Label: Op-code Operand@); Comment
For example, to add the content of AL and BL registers to get the result in AL, we use
the following assembly instruction.
Please note that NEXT is the label field. It is giving an identity to the statement. It is
an optional field, and is used when an instruction is to be executed again through a
L.OOP or GO TO. ADD is symbol~cop-code, for addition operation. AL and BL are
the two operands of the instructions. Please note that the number of operands is
i -
c~ependentupon the instructions. 8086 instructions can have zero, one or two
operands. An operand in 8086 can be:
1.
2.
A register .
A memory location
3. A constant called literal
4. A label. I
Comments in 8086 assembly start with a semicolon, and end with a new line. A long
comment can be extended to more than one line by putting a semicolon at the
beginning of each line. Comments are purely optional, however recommended as they
provide program documentation. In the next few sections we look at the instruction set
of the 8086 microprocessor. These instructions are grouped according to their
functionality.
Microprocesm ,
\
masking off the upper nibble of each ;and 7 CH = 09h Architecture
byte. Then ADD instruction is used to AAD
convert the unpacked BCD digits in ; adjust to binary before
AL and AH registers to adjust them to ;division AX= 0043 =
equivalent binary prior to division. ;043h = 67 Decimal
Such division will result in unpacked DIV CH
BCD quotient and remainder. The PF, ;Divide AX by unpacked
SF, ZF flags are updated, while the ; BCD in CH
AF, CF, and the OF flags are left ; AL = 07 unpacked BCD
undefined. ;AH = 04 unpacked BCD
;PF=SF=ZF=O
CBW Fill upper-byte or word with copies ; AL = 1001 1011 = - 155
of sign bit of lower bit. This is called ; decimal AH = 00000000
sign extension of byte to word. This CBW ;convert signed
instruction does no1 change any ;byte in AL to signed
flags. This operatio11is done with AL ; word in AX = 11111111
register in the result being stored in ; 10011011 = - 1% decimal
*
AX.
CWD Fill upper word or double word with ; DX : 0000 0000 0000 0000
sign bit of lower word. This ;AX:1111000001010001
instruction is an extension of the CWD
previous instruction. This instruction ;DX:AX=
;
1111 1111 1111 1111:
0000 0101 0001
results in sign extension of AX
register to DX:AX double word.
These instructions are used at the bit level. These instructions can be used for testing a
zero bit, set or reset a bit and to shift bits across registers. Let us look into some such
' NOT
' MNEMONIC
des
DESCRIPTION
Complements each bit to produce
EXAMPLE
; BX = 00 11 1010 000 1 0000
1's complement of the specified NOT BX
byte or word operand. The ; B X = 11000101 1110 1111
operand can be a register or a
memory operand.
AND des, src Bitwise AND of two byte or word ;BH = 001 1 1010 before
operands. The result is des f des AND BH, OFh
AND src. The source can be an ; BH = 0000 1010
immediate operand a register, or a ; after the AND operation
memory operand. ne destination
can be a register or a memory
operand. Both operands cannot be
memory operands at the same
time. The CF and the OF flags are
both zero after the AND
operation. PF, SF and ZF area
updated, Afis left undefined.
OR des, src OR each corresponding bits of the ; BH = 001 l 1010 before
byte or word operands. The other OR BH, OFh
operands rules are same as AND. ; BH = 001 1 1111 after
des C des OR src
XOR des,src XOReachcorrespondingbitina ;BX =0011110101101001
byte or word operands rules are ; CX = 00000000 11111111
two same as AND and OR. XOR BX,CX
des C Des + src ;BX=0011110110010110
;Please note, that the bits in
;the lower byte are inverted.
bsseqbly Language TEST des, src I @ID the operands to update
--' ;AL.= 0101 0001
RriQjogramyping
flags, but-donot change operands TEST AL, 80h.
value. It can be used to ~ eand
t ; This iflsmction would
.test conditions.CF and OF are ;test if b e MSB bit 9f the &
, both set to zero, PF, SF and ZF ;register is zero or one. After
e are all u&ted, @ is left ;the TEST operation ZF will
. : /., . , .undefme&aftqrthe operation,
;BX= 01000100
MOV.CL, 02
SHR BX, CL
;with same BX, the
;result would be
; BS = 0010 0100
;i+L=OOOl 1101 = +29
;decimal, CF = 0
MSB to that of old MSB. This is ,SAR 4L,01
also called arithmetic shift ,;AL=0000 1110=+14
, , operation, as it does not change ;decimal, CF = 1
k MSB, which is sign bit of a ;OF = PF = SF = ZF = 0
I - numb&:
SAR BH,Ol
; B H = 1111 1OO1=-7
.: ;decimal, CF =1
., 1 ,
2. > . ,sfate
< .
True or False in the context of 8086 assembly language.
(a) LEA and MOV instruction serve the same purpose. The only difference
between the two is the type of operands they take.
(e)
'
Suppose .ALc h a i n s 0 110 010 f and CF is set, then instructions ROL AL
and RCL AL will produce the same results.
Assembly Language
Programming 1.5.4 Program Execufion Transfer Instructions
These instructions are the ones that causes change in the sequence of execution of
instruction. This change can be through a condition or sometimes may be
unconditional. The conditions are represented by flags. For example, an instruction
may be jump to an address if zero flag is set, that is the last ALU operation has
resulted in zero value. These instructions are often used after a compare instruction, or
some arithmetic instructions that are used to set the flags, for example, ADD or SUB.
LOOP is also a conditional branch instruction and is taken till loop variable is below a
certain count.
Please note that a "I" is used to separate two mnemonics which represent the same
instruction.
MNEMONIC DESCRIPTION EXAMPLE
CALL proc 1 I This function results in a I CALL procl
procedure1 function call. The CALL proc2
return address is saved on the The new instruction
stack. There are two basic types address is determined by
of CALLS. NEAR or Intra- name declaration proc 1 is
Segment,calls: if the call is made a near procedure, thus,
to a procedure in the same only IP is involved. proc2
segment as the calling program. involves new CS: IP pair.
FAR or Inter segment call: if the On call to proc 1
call is made to a procedure in the stack C IP
segment, other than the calling IP C address offset of
program. The saved return proc 1
address for NEAR procedure on call to proc2
call is just the IP. For FAR Stack [top] C CS
Procedure call IP and CS are Stack [top] C IP
saved as return address. CS C code segment of
proc2
IP C address offset of
proc2
Here we assume that procl
is defined within the same
segment as the calling
procedure, while proc2 is
defined in another
segment. As far as the
calling program is
concerned, both the
procedures have been
called in the same manner.
But while declaring these
procedures, we declare
procl as NEAR procedure
and proc2 as FAR
procedure, as follows:
procl PROC NEAR
proc2 PROC FAR
A procedure can also be called LEA BX, procl
indirectly, by first initializing ;initialize BX with the
some 16-bit register, or some ;offset of the procedure
other memory location with the ;procl
new addresses as follows. CALL BX
;CALL procl indirectly
;using BX register
RET number It returns the control from RET 6
27 .-
Microprocessor
procedure to calling program. ; In this case, 8086 Architecture
Every CALL should be a RET ; increments the stack
instruction. A RET instruction, ;pointer by this number
causes return from NEAR or ; after popping off the 1P
FAR procedure call. For return ; (for new) or IP and CS
from near procedure the values ;registers (for far) from
of the instruction pointer is ; the stack. This cancels
restored from stack: While for ;the local parameters, or
far procedure the CS:IP pair get ;temporary parameters
is restored. RET instruction can ;created by the
also be followed by a number. ; programmer. RET
; instruction does not
; affect any flags.
Unconditionally go to specified JMP CONTINUE
address and get next instruction ; CONTINUE is the label
from the label specified. The ; given to the instruction
label assigns the instruction to ; where the control needs
which jump has to take place ; to be transferred.
within the program, or it could JMP BX
be a register that has been ; initialize BX with the
initialised with the offset value. ; offset of the instruction,
JMP can be a NEAR JMP or a ; where the control needs
1
Q
I
Microprocessor
instruction assumes that: in the memory. Source string Architecturca
Source string is in Data starts at offset 20h and the
segment. destination string starts at
Destination string is in extra offset 30h. Length of the
data segment source string is 10 bytes. To
SI stores offset of source copy the source string to the
string in extra segment destination string, proceed as
DI stores offset of destination follows:
string is in data segment MOV AX, 1000h
CX contains the count of MOV DS,AX
operation ; initialize data segment and
A single bvte transfer rewires: MOV ES,AX
MOV CX, 10
; load leagth of string to CX
; as counter
REP MOVSB
; Decrement CX and
; MOVSB until
; CX =o
; after move SI will be one
; greater than offset of last
; byte in source string, DI
; will be one greater than
; offset of last destination
; string. CX will be equal
:to zero.
CMPSICMPSBI It compares two string bytes or MOV c x , 1 0
, CMPSW words. The source string and the MOV S1,OFFSET SRC-STR
i destination strings should be ; offset of source
present in data segment and the ; string in SI
extra segment respectively. SI and MOV DI, OFFSET DES-STR
DI are used as in the previous ; offset of destination
instruction. CX is used if more ; string in DI
than one bytes or words are to be REPE CMPSB
compared, however for such a case ; Repeat the comparison of
appropriate repeating prefix like ; string bytes until
REP, PEPE etc. need to be used. ; end of string or until
;compared bytes are not
I ;equal.
It scans a string. Compare a string ( MOV AL, ODh
byte with byte in AL or a string ; Byte to be scanned
word with a word in AX. The ; for in AL
instruction does not change the MOV D1,OFFSET DES-STR
operands in AL (AX) or the MOV CX,lO
operand in the string. The string to REPNE SCAS DES-STR
be scanned must be present in the ; Compare byte inDES-STR
extra segment, and the offset of the ; with byte in A .register
string must be contained in the DI ( ;Scanning is repeated while ; 1
register. You can use CX if the bytes are not equal and ;
operation is to be repeated using it is not end of string. If a
REP prefixes. .; carriage return ODh is
;found, ZF = DI will point ;
Assembly Language
Programming at the next byte after the
; carriage return. If a
; carriage return is not
; found then, ZF = 0 and
; CX = 0. SCASB or
; SCASW can be used to
;explicitly state whether
; the byte comparison or the ;
word comparison is
; required.
LODS/LODSB/ It loads string byte into AL or a MOV S1,OFFSET SRC-STR
LODSW string word into AX. The string LODS SRC-STR
byte is assurr,ed to be pointed to by ; LODSB or LODSW can
SI register. ~ f t e the
r load, the SI ;be used to indicate to the
pointer is automatically adjusted to ; assembler, explicitly,
point to the next byte or word as ; whether it is the byte that
the case may be. This instruction ; is required to be loadedbi
does not affect any flag. :the word. I
STOSISTOSBI It stores byte fiom AL or word
STOSW fiom AX into the string present in
the extra segment with offset given
by DI. After the copy, DI is
automatically adjusted to point to
the next byte or word as per the
instruction. No flags are affected.
Well, 8086 only allows you to control certain control flags that causes the processing
in a certain direction, processor synchronization if more than one processors are
attached through LOCK instruction for buses etc.
Note: Please note that these instructions may not be very clear to you right now. Thus,
some of these instructions have been discussed in more detail in later units. You must I
MNEMONIC DESCRIPTION EXAMPLE
STC It sets cany flag to 1.
CLC It clears the carry flag to 0..
CMC It complements the state of the CMC; Invert the carry flag
canyflagfiomoto 1 or 1 t o o a s '
the case may be.
STD It sets the direction flag to 1. The
string instruction moves either
forward (increment SI, DI) or
backward (decrement SI, DI)
based on this flag value. STD
ins&ction does not affect any
other flag. The set direction flag
causes stings to move fiom right
to left.
CLD This is opposite to STD, the string CLD
2
t
Microprocessor
operation occurs in the reverse ;Clear the direction flag Architecture
direction: ;so that the string pointers
;auto-increment.
MOV AX, 1000h
MOV DS, AX
;Initialize data segment
;and extra segment
MOV ES, AX
i MOV SI, 20h
;Load offset of start of
;source string to SI
MOV DI,30h
;Load offset of start of
;destination string to DI
MOV CX,10
;Load length of string to
;CX as counter
REP MOVSB
;Decrement CX and
; increment
;SI and DI to point to next
;byte, then MOVSB until
;CX=O
There are many process control instructions other than these; you may please refer to
further reading for such instructions. These instructions include instructions for setting
and closing interrupt flag, halting the computer, LOCK (locking the bus), NOP etc.
Index register (SI, DI): These registers are used as index registers in data andlor extra
4. In the instruction MOV BX, DX register addressing mode has been used.
0
fi. In the instruction MOV BX,ES:COUNTER the second operand is a direct
o~erand. I 7
I. In the instruction ADD CX, [DI] [BX] the second operand is a based index /
i 1.7 SUMMARY
.
In this unit, we have studied one of the most popular series of microprocessors, viz.,
Intel 8086. It serves as a base to all its successors,. 8088, 80186, 80286,80486, and
Pentium. The successors of 8086 can be directly run on any successors. Therefore,
though, 8086 has become obsolete from the market point of view, it is still needed to
understand advanced microprocessors.
1.8 SOLUTIONSIANSWERS
1 Check Your Progress 1
1. It improves execution efficiency by storing the next instruction in the register
queue.
2. (a) False
(b) False
(c) True
(d) False
(e) False