SlideShare a Scribd company logo
1 of 124
80386DX-Basic Programming
Model andApplications
Instruction Set
Prof.Pratima Kadam
Assistant Professor
Computer Engineering Department
1
Course Objectives:
o To learn the architecture andprogrammer„s model of advanced
processor.
o To understand the system level features and processes of
advanced processor .
o To acquaint the learner with application instruction set and logic
to build assembly language programs.
o To understand debugging and testing techniques confined to
80386 DX.
Course Outcomes:
• On completion of the course,student will be able to–
• Apply the assemblylanguageprogramming to develop smallreal
life embedded application.
• Understand the architecture of the advanced processor
thoroughly to use the resources for programming.
• Understand the higher processor architectures descended from
80386 architecture .
2
What is Microprocessor
3
âš« A microprocessor, sometimes called a logic chip,
is a computer processor on a microchip.
⚫ It is also called as “Heart of Computer.”
âš« The microprocessor contains all, or most of, the
central processing unit (CPU) functions.
âš« A microprocessor is designed to perform
arithmetic and logic operations that make use of
small number-holding areas called registers.
âš«Typical microprocessor operations include
adding, subtracting, comparing two
numbers, and fetching numbers from
one area to another.
âš«These operations are the result of a set of
instructions that are part of the
microprocessor design.
4
Three basic characteristics differentiate
microprocessors:
5
âš« Instruction set: The set of instructions that the
microprocessor can execute.
âš« Bandwidth : The number of bits processed in a single
instruction.
âš« Clock speed : Given in megahertz (MHz), the clock
speed determines how many instructions per second the
processor can execute.
In both cases, the higher the value, the more powerful the
CPU.
For example, a 32-bit microprocessor that runs at
50MHz is more powerful than a 16-bit microprocessor
that runs at 25MHz.
Architecture of 8086
6
Pin Diagram 8086
7
âš«8086 can be work in two modes
âš« Minimum Mode:For single processor
systems.
âš« Maximum Mode:For system with two or
more processors.
âš«Depending upon modes signals can
be divided into
âš« Signals having common functions in both modes
âš« Signals for Minimum Mode
âš« Signals for Maximum Mode
8
Logical to physical address
Translation in 8086
9
âš« The 20-bit address of a byte is called its
PhysicalAddress.
âš« But,it is specified as a LogicalAddress.
âš« Logical address is in the form of:
âš« BaseAddress :Offset
the memory
âš« Offset
location
is the displacement of
from the starting location of the
segment.
Example
10
âš«The value of Data Segment Register (DS) is
2222 H.
âš«To convert this 16-bit address into 20-bit, the
BIU appends 0H to the LSBsof the address.
âš«After appending, the starting address of the
Data Segment becomes 22220H.
âš«If the data at any location has a logical
address specified as:
âš« 2222 H :0016 H
âš«Then, the number 0016 H is the offset. 2222
H is the value of DS.
To calculate the physical address of the memory,
BIU uses the following formula:
PhysicalAddress =
StartingAddress of Segment + Offset
To find the starting address of the segment, BIU
appends the contents of Segment Register with 0H.
Then,it adds offset to it.
Therefore:
EA = 22220 H
+ 0016 H
------------
22236 H
11
12
New in 80386
13
âš«Data bus = 32bit,all registers of 32 bit and
Eflags is also of 32 bit.
âš«Address Bus = 32 bit.(4 GB Memory)
âš«Enhanced Memory Management Unit.
âš«Supports Virtual addressing.
âš«Faster execution of arithmetic operations.
âš«Works in :-
âš«1.Real Mode (8086)
âš«2.Protected Mode
âš«3.Virtual Mode
âš«Additional Interrupts in IVT.
FEATURES
14
⚫ Manufactured using Intel‟s complementary High-
performance Metal-oxide-semiconductor 3
process.
âš« 8 general purpose registers of 32-bit .
âš« 32-bit Address and Data Bus.
âš« Supports 8 bit,16 bit,32 bit data.
âš« Prefetch queue of 16B.
âš« Very Large address space i.e VM of 64 TB and
PM of 4GB.
âš« Supports Segmentation and Paging.
âš« 4 levels of protection.
âš« Uses 3-stage pipelines.
âš« Supports multitasking with protection.
âš« On chip cache memory for TLB.
âš« Pipelined instruction Execution.
âš« Memory Management unit.
âš« High speed numeric support via 80287
and 80387 coprocessor.
âš« It can operate in real , protected and virtual
mode.
15
Family tree of 80386
16
Chip Introduction Data bus
Addres
s Bus
Memory
4004 1971 4 8 256 Byte
8008 1972 8 8
256 Byte
8080 1974 8 16 64 KB
8086/88 1978 16/8 20
1M
80186/188 1982 16/8 20
1M
80286 1983 16 24
16M:Clock speed
is high
80386
DX(1986:not
compatibility)
SX(1988: mostly
used, Not Co-
Processor)
DX:32+132
pin
SX:16+100
pin
32
24
DX:4G (275,000
transistor
)
SX:16MB
80486 32 32
Memory Size: 4G
+16K cache
Difference between 80386 SX/DX
8-bit and 16-bit
17
•Both have the same internal architecture.
•Lower cost package and the ease of interfacing to
memory and peripherals make ,
•SX suitable for use in low cost systems.
Introduction to 80386
18
o The 80386 is an advanced 32-bit microprocessor optimized
for multitasking operating systems and designed for
applications needing very high performance.
o The 32-bit registers and data paths support 32-bit addresses
and data types.
o The processor can address up to 4 gigabytes of physical
memory and 64 terabytes (246 bytes) of virtual memory.
o The on-chip memory management facilities include address
translation registers, advanced multitasking hardware, a
protection mechanism, and paged virtual memory.
o Special debugging registers provide data and code
breakpoints even in ROM-based software.
Features of 80386
19
â–Ł The 80386 has three processingmodes:
â–Ł 1.Protected Mode:
o Protected mode is the natural 32-bit environment of the 80386
processor.
o In this mode all instructions and features are available.
â–Ł 2.Real-Address Mode.
o Real-address mode is the mode of the processor immediate after
RESET.
o In real mode the 80386 appears to programmers as afast 8086 with
some new instructions.
o Most applications of the 80386 will use real mode.
â–Ł 3.Virtual 8086 Mode:
o Virtual 8086 mode is a dynamic mode which can switch repeatedly and
rapidly betweenV86 mode and protected mode.
o The CPU entersV86 mode from protected then leavesV86 mode and
enters protected.
Internal Architecture
20
Architecture of 80386
21
âš« The Internal Architecture of 80386 is divided into 3
sections:
â—¦ i) Central processing unit (CPU)
đźž„Execution unit (EU) and
đźž„Instruction unit (IU)
â—¦ ii) Memory management unit (MMU)
đźž„Segmentation unit
đźž„ Paging unit.
â—¦ iii) Bus interface unit( BIU)
Central Processing Unit
22
âš« Central processing unit is further divided into
Execution unit and Instruction unit.
• Execution unit has 8 General purpose and 8 Special
purpose registers which are either used for handling
data or calculating offset addresses.
âš« The Instruction unit decodes the opcode bytes
received from the 16-byte instruction code queue
and arranges them in a 3- instruction decoded
instruction queue.
âš«After decoding them pass it to the control
section for deriving the necessary control
signals. The barrel shifter increases the
speed of all shift and rotate operations.
• The multiply / divide logic implements the
bit-shift-rotate algorithms to complete the
operations in minimum time.
• Even 32- bit multiplications can be executed
within one microsecond by the multiply /
divide logic.
23
Memory Management Unit
24
âš«The Memory management unit consists of a
Segmentation unit and a Paging unit.
âš«Segmentation unit allows the use of two
address components, viz. segment and offset
for relocability and sharing of code and data.
âš«Segmentation unit allows segments of size
4Gbytes at max.
âš«The Paging unit organizes the physical
memory in terms of pages of 4 kbytes size
each.
âš«Paging unit works under the control of the
segmentation unit, i.e. each segment is further
divided into pages.
âš«The virtual memory is also organizes in terms
of segments and pages by the memory
management unit.
25
âš« The Segmentation unit provides a 4 level protection
mechanism for protecting and isolating the system
code and data from those of the application program.
âš« Paging unit converts linear addresses into physical
addresses.
âš« The control and attribute PLA checks the privileges
at the page level. Each of the pages maintains the
paging information of the task.
âš« The limit and attribute PLA checks segment limits
and attributes at segment level to avoid invalid
accesses to code and data in the memory segments.
26
Bus Interface Unit
27
âš« The Bus control unit has a prioritizer to resolve
the priority of the various bus requests.
âš« This controls the access of the bus. The address
driver drives the bus enable and address signal A0–
A31.
âš« The pipeline and dynamic bus sizing unit handle
the related control signals.
âš« The data buffers interface the internal data bus
with the system bus.
MEMORY ORGAN IZATION AND
SEGMENTATION
28
âš« The physical memory of an 80386 system is organized as a
sequence of 8-bit bytes.
âš« Each byte is assigned a unique address that ranges from
0 to amaximum of 232 -1.(4 Gigabytes).
âš« The model of memory organization determined by
systems-software designers.
âš« Two model of memory
âš« 1.Flat model:single array of up to 4 GB.
âš« A pointer into this flat address space is a32-bit ordinal
number that may range from 0 to 232 -1.
MEMORY ORGAN IZATION AND
SEGMENTATION
29
linear
âš« Segmented model: collection of up to
16,383 address spaces.
âš« Viewed by an applications program (called the logical
address space)
âš« The processor maps the 64 terabyte logical address space
onto the physical address space (4 GB) by the address
translation mechanisms.
âš« Each of these linear subspaces is called asegment.
âš« A segment is aunit of contiguous address space
âš« Segment sizes may range from 1 byte up to a maximum of
232 bytes (4 gigabytes).
âš«
MEMORY ORGAN IZATION AND
SEGMENTATION
âš« A complete pointer in this address space consists of two
parts.
âš« l. A segmentselector
,which isa16-bit field that identifies a
segment.
âš« 2. An offset,which is a32-bit ordinal that addresses to the
byte level within asegment.
30
DataTypes:
31
âš« Bytes, words, and doublewords are the fundamental
data types
âš« Integer: A signed binary numeric value contained in a 32-
bit doubleword,16-bit word, or 8-bit byte. All operations
assume a2's complement representation.
- range of an 8-bit integer is -128 through +127
- 16-bit integers may range from -32,768 through +32,767
- 32-bit integers may range from -231 through +231-1
Execution unit :DATA TYPES
âš« Fundamental data types:
32
âš« Ordinal: An unsigned binary numeric value contained
in a32-bit doubleword, 16-bit word, or 8-bit byte. All
bits are considered in determining magnitude of the
number.
- range of an 8-bit ordinal number is 0-255;
- 16 bits can represent values from 0 through 65,535;
- 32 bits can represent values from 0 through 232-1.
âš« Near Pointer:A 32-bit logical address.A near pointer
is an offset within asegment.
âš« Far Pointer:A 48-bit logical address of two
components:a16-bit segment selector component and
a32-bit offset component.
âš« String: A contiguous sequenceof bytes, words, or
doublewords.A string may contain from zero bytes to
232-1 bytes (4 gigabytes).
33
âš« Bit field: A contiguous sequence of bits. A bit field may
begin at any bit position of any byte and may contain up
to 32 bits.
âš« Bit string: A contiguous sequence of bits.A bit string
may begin at any bit position of any byte and may
contain up to 232-1 bits.
âš« BCD: A byte (unpacked) representation of adecimal
digit in the range0 through 9. Unpacked decimal
numbers are stored as unsigned byte quantities. One
digit is stored in each byte.
âš« Packed BCD: A byte (packed) representation of two
decimal digits, each in the range 0 through 9. One digit
is stored in each half-byte.
34
MEMORY ORGA N IZATION AND
SEGMENTATION
âš« .
35
Registers
36
The 80386 has eight 32-bit general purpose registers
which may be used as either 8 bit, 16 bit or 32 bit
registers.
•A 32-bit register known as an extended register, is
represented by the register name with prefix E.
•Example :A32 bit register corresponding to
AX is EAX
•So the general purpose registers of 386 are EAX,
EBX, ECX, EDX, EBP, ESP, ESI and
EDI
Registers
37
âš« BP, SP, SI, DI represents the lower 16 bit of their 32 bit
counterparts, and can be used as independent 16 bit
registers.
âš« The 16 bit flag register is available along with 32 bit
counterpart EFLAGS.
Register Set
38
âš«The 80386 contain total 16 registers
These registers grouped as:
1. General
2. Segment
3. Status and Instruction
4. Control Registers
5. SystemAddress Registers
6. Debug Registers
7. Test Registers
General Registers
39
Segment Registers
40
SEGMENT REGISTERS
o Six segments of memory may be immediately accessible to an
executing 80386 program.
o The segment registers CS, DS, SS, ES, FS, and GS are used
to identify these six current segments.
o Each of these registers specifies a particular kind of segment,
as characterized by the associated mnemonics ("code," "data,"
or "stack").
41
CS Register
âš«CS: The segment containing the currently executing
sequence of instructions is known as the current code
segment.
âš« The 80386 fetches all instructions from this code
segment, using as an offset the contents of the
instruction pointer.
42
S
Sand ES,DS,FS,GSRegister
43
âš« SS:Subroutine calls, parameters, andprocedure activation
records usually require to allocate memory as astack.
âš« All stack operations use the S
S register to locate the
stack.
âš« Data Registers: The DS, ES, FS, and GS registers
allow the specification of four data segments.
âš« Access different types of data structures;
âš« Types of data structures:
âš« Current module, Exported data, Dynamically created data
structure and data Shared with another task.
Status and IP
44
Flag Register
âš« The Flag register of 80386 is a32 bit register.
âš« Out of the 32 bits,Intel has reserved bits D18 to D31,D5 and D3 and
set to 0
âš« While D1 is always set at 1.
âš« Twoextra new flagsareaddedto the 80286flagto derive the flag
register of 80386.
âš« They areVM and RFflags.
45
Flag Register
46
VM Bit - Virtual Mode Flag
47
âš« If this flag is set toVM=1,the 80386 enters the virtual
8086 mode within the protection mode.
âš« WhenVM bit is 0,386 operates in protected mode
âš« This is to be set only when the 80386 is in protected mode.
âš« This bit can be set using IRET instruction or any task
switch operation only in the protected mode.
RF-Bit Resume Flag
48
âš« If RF=1, 386 ignores debug faults and does not take
another exception so that an instruction can be restarted
after anormal debug exception.
âš« If RF=0, 386 takes another debug exception to service
debug faults
âš« This flag is used with the debug register breakpoints.
âš« It is checked at the starting of every instruction cycle and
if it is set=1, any debug fault is ignored during the
instruction cycle.
âš« The RF is automatically reset after successful execution of
every instruction, except for IRET and POPF instructions
RF- Resume Flag...
49
âš« Also, it is not automatically cleared after the successful
execution of JMP,CALL and INT instruction causing a task
switch.
âš«VM (Virtual 8086 Mode): If set while the
Intel386 DX is in Protected Mode, the
Intel386 DX will switch to Virtual 8086
operation.
âš«The VM bit can be set only in Protected
Mode, by the IRET instruction (if current
privilege level e 0)
âš«RF (Resume Flag): The RF flag is used in
conjunction with the debug register
breakpoints.
âš«When RFis set, it causes any debugfault to
be ignored on the next instruction.
50
âš«NT (Nested Task): This flag applies to
Protected Mode.
âš«NT is set to indicate that the execution of
this task is nested within another task
âš«The value of NT in EFLAGS is tested by
the IRET instruction to determine
whether to do an inter-task return or an
intra-task return.
51
IOPL (Input / Output Privilege Level)
52
âš«This two-bit field applies to Protected Mode.
IOPL indicates the numerically maximum
CPL(current privilege level) value permitted
to execute I/O instructions without
generating an Exception
âš«It also indicates the maximum CPL value
allowing alteration of the IF (INTR Enable
Flag) bit when new values are popped into the
EFLAG register
âš«IF (INTR Enable Flag): The IF flag, when set,
allows recognition of external interrupts
signaled on the INTR pin.
âš«TF (Trap Enable Flag): When TF is set, the
Intel386 DX generates an exception 1 trap
after the next instruction is executed.
âš«When TF is reset, exception 1 traps occur
only as a function of the breakpoint
addresses loaded into debug registers DR0-
DR3.
53
âš«OF (Overflow
54
Flag) : It is set if the
operation resulted in a signed overflow.
Signed overflow occurs when the operation
resulted in carry/borrow into the sign bit
(high-order bit) of the result.
âš«DF (Direction Flag) : DF defines whether
ESI and/or EDI registers post-decrement or
post-increment during the string
instructions.
âš«Post-decrement occurs if DF is set
Flags
55
âš«The arithmetic instructions use CF, SF, ZF,
AF
,PF
,CF
⚫The control flag DF controls “STRING”
instruction
âš«Clearing DF flag causes string instructions
to auto increment or to process string
from low to high address
Hidden Registers/
Program invisible registers/
Special Registers
56
Control Registers
57
âš« The 80386 has four 32 bit control registers CR0,
CR1,CR2 and CR3 to hold global machine status.
âš« CR1 is not used in 386 and reserved for future use.
âš« Load and store instructions are available to access
these registers.
Control Registers
58
SystemAddress Registers
59
âš« The 386 supports 4 types of descriptor table:
• Global descriptor table (GDT),
• Local descriptor table (LDT),
• Interrupt descriptor table (IDT)
• Task state segment descriptor (TSS).
âš« Four special registers are defined to hold the base address
of these tables
• Global descriptor table Register (GDTR)
• Local descriptor table Register (LDTR)
• Interrupt descriptor table Register (IDTR)
• Task state segment descriptor Register (TR).
Debug Registers
60
âš« Intel has provided a set of 8 debug registers for
hardware debugging.
âš« DR4 and DR5 are Intel reserved.
âš« The initial four registers DR0 to DR3 store four
program controllable breakpoint addresses,
âš« DR6 and DR7 respectively hold breakpoint status
and breakpoint control information.
Debug Registers
61
DR7
DR6
DR5
DR4
DR3
DR2
DR1
DR0
breakpoint control info
breakpoint status
RESERVED
RESERVED
Linear breakpoint address 3
Linear breakpoint address 2
Linear breakpoint address 1
Linear breakpoint address 0
31 0
Test Registers
62
âš«Two test register are provided by
80386 for page caching namely test
control and test status register.
INSTRUCTION FORMAT
âš« The information encoded in an 80386 instruction
includes aspecification of ;
âš« Operation to be performed (Opcode).
âš« Type of the operands to be manipulated,
âš« Location of these operands.
Opcode Source(M/ Reg) Destination(M/ Reg)
63
Operand Selection
64
âš« In the instruction itself(immediate operand)
âš« In aregister
âš« In memory
âš« At an I/O port
âš« Implicit operand
âš« Explicit operand
âš« Implicit and Explicit Operand
INSTRUCTION FORMAT
65
âš« Two-operand instructions of the 80386 permit
operations of the following kinds:
⚫ • Register-to-register
⚫ • Register-to-memory
⚫ • Memory-to-register
⚫ • Immediate-to-register
⚫ • Immediate-to-memory
âš« Certain string instructions and stack manipulation
instructions transfer data from memory to memory.
âš« Push and pop stack operations allow transfer between
memory operands and the memory-based stack.
âš«Immediate Operands
âš«Register Operands
âš«Memory Operands
âš«Segment Selection
66
EffectiveAddress Computation
67
EffectiveAddress Computation…
68
âš« Displacement: Indicates the offset of the
operand . Used to directly address a statically
allocated scalar operand.
âš« Base: Offset is specified indirectly in one of the
general registers,as for based variables.
âš« Base+displacement:
âš« To index into static array when element size is not 2,4,8 bytes.
âš« Access item of record. Displacement component locates an item
within record.
âš« (Index*scale) + displacement: Provides efficient
indexing into a static array when element size is 2,4,8
bytes.
EffectiveAddress Computation…
69
âš« Base + Index + Displacement: Two registers
used together support either a two dimensional
array (where displacement determine beginning
of array) or one of several instances of an array
of records (where displacement indicates an
item in the record.)
âš« Base + (Index * Scale) + displacement:
This combination provides efficient indexing of
a two-dimensional array when element of the
array are 2,4,8 bytes wide.
Interrupts and Exceptions
70
program
âš« Two mechanism for
interrupting execution
âš« Exceptions are synchronous events that are
the responses of the CPU to certain conditions
detected during the execution of an instruction.
âš« Interrupts are asynchronous events typically
triggered by external devices needing attention.
Interrupts and Exceptions…
71
APPLICATIONS INSTRUCTION SET
âš«To write application software for the 80386
executing in protected virtual-address
mode.
âš«DATA MOVEMENT INSTRUCTIONS
âš«They fall into the following classes:
âš«1. General-purpose data movement
instructions.
âš«2.Stack manipulation instructions.
âš«3.Type-conversion instructions.
72
General-Purpose Data Movement
Instructions
73
âš« MOV (Move) transfers a byte, word, or double word from
the source operand to the destination operand.
âš« The MOV instruction is useful for transferring data
along any of these paths
⚫ •To aregister from memory
⚫ •To memory from aregister
⚫ • Between general registers
⚫ • Immediate data to aregister
⚫ • Immediate data to amemory
âš« XCHG (Exchange) swaps the contents of two operands.
Stack Manipulation Instructions
74
âš« PUSH (Push) decrements the stack pointer (ESP), then
transfers the source operand to the top of stack indicated
by ESP
âš« PUSH is often used to place parameters on the stack
before calling aprocedure.
âš« The PUSH instruction operates on memory
operands, immediate operands,and register .
âš« PUSHA (Push All Registers) saves the contents of the
eight general registers on the stack..
âš« The processor pushesthe general registers on the stack
in the following order:
âš« EAX, ECX, EDX, EBX, the initial value of ESPbefore EAX
was pushed,EBP
,ESI,and EDI.
Type Conversion Instructions
75
âš« The type conversion instructions convert bytes into words,
words into double words, and double words into 64-bit
items (quad-words).
âš« CWD,CDQ,CBW,and CWDE
âš« CWD (ConvertWord to Doubleword)
âš« CBW (Convert Byte to Word)
âš« CDQ (Convert Doubleword to Quad-Word)
âš« CWDE (Convert Word to Doubleword Extended)
âš« MOVSX (Move with Sign Extension)
âš« MOVZX (Move with Zero Extension)
BINAR
YARITHMETIC INSTRUCTIONS
** Addition and Subtraction Instructions
76
âš« ADD D ,S (sets CF is there is carry)
âš« ADC D ,S (D= D+S+C)
âš« INC D (Increment Byte,Word or Doubleword by 1)
âš« SUB D ,S (sets CF is there is borrow)
âš« SBBD ,S (D= D-S-C)
âš« DEC D (Decrement Byte,Word or Doubleword by 1)
BINAR
YARITHMETIC INSTRUCTIONS
** Comparison and Sign Change Instructions
77
âš«CMP D,S (Destination-Source)
Updates OF
,S
F
,ZF
,AF
,PFand CF
âš«NEG D
Subtracts asigned integer operand from zero
BINAR
YARITHMETIC INSTRUCTIONS
** Multiplication and Divide Instructions
78
âš«MUL S
âš«IMUL S
âš«DIV S
(Unsigned Integer Multiply)
(Signed Integer Multiply)
(Unsigned Integer Divide)
Dividend Quotient Remainder
AX AL AH
DX:AX AX DX
EDX:EAX EAX EDX
âš«IDIV S (Signed Integer Divide)
Uses same registers as in DIV
DECIMAL ARITHMETIC INSTRUCTIONS
79
âš« Decimal Arithmetic is performed by combining the binary
arithmetic instructions with decimal arithmetic
instructions.
âš« Decimal Arithmetic instructions are used in one of the
following ways
- To adjust the results of a previous binary arithmetic
operation to produce a valid packed or unpacked decimal
result.
- To adjust the inputs to a subsequent binary arithmetic
operation so that the operation will produce a valid
packed or unpacked decimal result.
âš« These instructions operate only on the AL or AH registers.
Most utilize the AF flag.
DECIMAL ARITHMETIC INSTRUCTIONS
** Packed BCDAdjustment Instructions
80
âš« DAA (DecimalAdjust afterAddition)
- Adjusts the result of adding two valid packed decimal
operands in AL.
output
- DAA instruction gives us correct decimal
instead of hexadecimal.
- Carry flag is set if carry was needed.
âš« DAS (DecimalAdjust after Subtraction)
- Adjusts the result of Subtracting two valid packed
decimal operands inAL.
- DAS instruction gives us correct decimal output instead
of hexadecimal.
- Carry flag is set if borrow was needed.
DECIMAL ARITHMETIC INSTRUCTIONS
** Unpacked BCDAdjustment Instructions
81
âš« AAA (AsciiAdjustAfterAddition)
- AL contain valid unpacked decimal number andAH=00
- AAA must always follow addition of two
unpacked decimal operands in AL.
- Carry flag is set and AH is incremented if a carry is
necessary.
âš« AAS (AsciiAdjustAfter Subtraction)
- AL contain valid unpacked decimal number andAH=00
- AAS must always follow Subtraction of one unpacked
decimal operands from another inAL.
- Carry flagis set andAH is incremented if aborrow is
necessary.
DECIMAL ARITHMETIC INSTRUCTIONS
** Unpacked BCDAdjustment Instructions
82
âš« AAM (AsciiAdjustAfter Multiplication)
- Corrects multiplication of two unpacked decimal number.
- The high order digit is left in AH, the low order digit in AL.
âš« A A D (AsciiAdjustAfter Division)
- Modifies numerator in AH and AL for unpacked decimal
operands divide operation.
- Quotient produced will be valid unpacked decimal.
- The high order digit is left in AH, the low order digit in AL.
- Adjusts the result in AL and makeAH=00
LOGICAL INSTRUCTIONS
83
⦿ The group of logical instructionsincludes:
• The Boolean operation instructions
• Bit test and modify instructions
• Bit scan instructions
• Rotate and shift instructions
• Byte set on condition
The Boolean operation instructions
84
⦿ NOT (Not)
Inverts the bits in the specified operand to form aone‟s
complement of the operand. Has no effect on flags.
⦿ AND,OR, and XOR
AND- is useful instruction for turning aparticular bit off.
(Turn to 0)
OR- isuseful instruction for setting aparticular bit on. (Turn
to 1)
XOR- is useful instruction for clearing aregister.Or useful
for toggling particular bit without changing other bits.
Bit test and modify instructions
âš« This group of instructions operates on asingle bit which
can be in memory or in ageneral register.
âš« These instructions first assignthe value of the selected
bit to CF
,the carry flag.
âš« Then a new value is assigned to the selected bit, as
determined by the operation.
85
Bit scan instructions
86
âš« These instructions scan a word or doubleword for
a one-bit and store the index of the first set bit
into a register.
âš« The bit string being scanned may be either in
a register or in memory.
âš« Affects ZF=1 if word is zero,otherwise clear ZF
âš« BSF (Bit Scan Forward) scans from low-order
to high-order (starting from bit index zero).
âš« BSR (Bit Scan Reverse) scans from high-order
to low-order (starting from bit index 15 of a word
or index 31 of a doubleword).
Shift and Rotate Instructions
87
âš«These instructions fall into the following
classes:
• Shift instructions
• Double shift instructions
• Rotate instructions
SHIFT INSTRUCTIONS
88
âš« The bits in bytes,words, and double words may be shifted
arithmetically or logically.
âš« CF always contains the value of the last bit shifted out of
the destination operand.
âš« OF is set if the value of the high-order (sign) bit
was changed by the operation.
âš« SAL (Shift Arithmetic Left)
âš« SHL (Shift Logical Left)
âš« SHR (Shift Logical Right)
âš« SAR (Shift Arithmetic Right)
âš« ROL (Rotate Left)
âš« ROR (Rotate Right)
âš« RCL (RotateThrough Carry Left)
SAL/SHL
⦿ SAL (Shift Arithmetic Left) shifts the destination byte, word, or double
word operand left by one or by the number of bits specified in the
count operand
⦿ The processor shifts zeros in from the right (low-order) side of the
operand as bits exit from the left (high-order) side.
⦿ Sal AX,CL
89
SHR (Shift Logical Right)
90
SAR (Shift Arithmetic Right)
âš« The processor preserves the sign of the operand by
shifting in 0 on the left (high-order) side if the value is
positive
âš« or by shifting by 1 if the value is negative.
âš« SAR is rounded toward negative infinity
91
DOUBLE-SHIFT INSTRUCTIONS
âš« These instructions provide the basic operations needed to
implement operations on long unaligned bit strings.
âš« The double shifts operate either on word or double word
operands,as follows:
âš« SHLD (Shift Left Double) :shifts bits of the R/M field to the left,
while shifting high-order bits from the Reg field into the R/M
field on the right.
âš« The result is stored back into the R/M operand.
âš« The Regfield is not modified.
92
SHRD (Shift Right Double) shifts bits of the R/M field to the right, while
shifting low-order bits from the Reg field into the R/M field on the left
93
ROTATE INSTRUCTIONS
94
âš« Rotate instructions allow bits in bytes, words, and double
words to be rotated.
âš« Bits rotated out of an operand are not lost as in a shift,
but are "circled" back into the other "end" of the operand.
âš« Rotates affect only the carry and overflow flags.
âš« CF may act as an extension of the operand.
âš« CF always contains the value of the last bit rotated out.
ROL and ROR
âš« ROL (Rotate Left) rotates the byte, word, or double word
destination operand left by one or by the number of bits
specified in the count operand .
âš«ROR(Rotate Right)
95
RCL and RCR
âš« It treats CF as a high-order one-bit extension of the
destination operand.
96
CONTROLTRANSFERINSTRUCTIONS
97
âš« UnconditionalTransfer Instructions:
âš« JMP- JMP is a one-way transfer of execution; it does not
save areturn address on the stack.
âš« CALL- activates an out-of-line procedure, saving on the
stack the address of the instruction following the CALL
for later use by aRET (Return) instruction.***stack
âš« RET- terminates the execution of aprocedure and
transfers control through aback-link on the stack to the
program that originally invoked the procedure.*** back
link on the stack EIP
âš« IRET- returns control to an interrupted procedure. IRET
differs from RETin that it also popsthe flagsfrom the
stack into the flags register.
ConditionalTransfer Instructions:
98
Conditional
99
âš« LOOP
âš« LOOPE (Loop While Equal) and LOOPZ (Loop While
Zero)
These instructions automatically decrement the ECX
register before testing ECX and ZF for the branch
conditions.
ECX=0 and ZF=0 ignore
âš« LOOPNE (Loop While Not Equal) and LOOPNZ (Loop
While Not Zero)
ECX=0 and ZF=1 ignore
âš« JCXZ (Jump if ECX Zero) branches to the label specified
in the instruction if it finds avalue of zero in ECX.
Software Generated Interrupts
100
âš« INT n (Software Interrupt) activates the interrupt
service routine that corresponds to the number coded
within the instruction. The interrupt service routine
terminates with an IRET instruction that returns control to
the instruction that follows INT.
âš« INTO (Interrupt on Overflow) invokes interrupt 4 if
OF is set.
âš« BO U ND (Detect Value Out of Range) verifies that
the signed value contained in the specified register lies
within specified limits. An interrupt (INT 5) occurs if the
value contained in the register is less than the lower bound
or greater than the upper bound.
STRINGAND CHARACTERTRANSLATION
INSTRUCTIONS
101
⦿ 1. A set of primitive string operations
⚫ MOVS — Move String
⚫ CMPS — Compare string
⚫ SCAS — Scan string
⚫ LODS — Load string
⚫ STOS — Store string
⦿ 2. Indirect, indexed addressing, with automatic incrementing or decrementing
of the indexes.
Indexes:
⚫ ESI —- Source index register
⚫ EDI — Destination index register
âš« Control flag:
⚫ DF — Direction flag
âš« Control flag instructions:
âš« CLD Clear direction flag instruction
⚫ STD — Set direction flag instruction
⦿ 3. Repeat prefixes
âš« REP Repeat while ECX not zero
âš« REPE/REPZ Repeat while equal or zero
âš« REPNE/REPNZ Repeat while not equal or not zero
Repeat Prefixes:
102
Indexing and Direction flag Control
103
âš« The addresses of the operands of string primitives are
determined by the ESIand EDI registers.
âš« ESI points to source operands. By default, ESI refers to a
location in the segment indicated by the DS segment
register. A segment-override prefix may be used, however,
to cause ESIto refer to CS,SS,ES,FS,or GS.
âš« EDI points to destination operands in the segment
they are
indicated by ES;no segment override is possible.
âš« The direction flag determines whether
incremented or decremented.
String Instructions
104
âš« MOVS (Move String) moves the string element pointed to by ESI to
the location pointed to by EDI. The MOVS instruction, when
accompanied by the REP prefix, operates as a memory-to-memory
block transfer.MOVSB,MOVSW,MOVSD
âš« CMPS (Compare Strings) subtracts the destination string element
(at ES:EDI) from the source string element (at ESI) and updates the flags
AF, SF,PF,CF and OF. If the string elements are equal, ZF=1; otherwise,
ZF=0. CMPSB compares bytes, CMPSW compares words, and CMPSD
compares doublewords.
âš« SCAS (Scan String) subtracts the destination string element at
ES:EDI from EAX, AX, or AL and updates the flags AF, SF,ZF, PF,CF and
OF.If values are equal,ZF=1;otherwise,ZF=0.
âš« LODS (Load String) places the source string element
at ESI into EAX for doubleword strings, into AX for
word strings, or into AL for byte strings.LODS
increments or decrements ESIaccording to DF
.
âš« STOS (Store String) places the source string
element from EAX, AX, or AL into the string at ES:DSI.
STOS increments or decrements EDI according to DF.
105
Instructions for Block Structured
Languages
106
âš« Instructions in this section provide machine-language
support for functions normally found in high-level
languages.
âš« ENTER: creates a stack frame that may be used to
implement the scope rules of block structured high-level
languages.
âš« LEAVE: A LEAVE instruction at the end of a procedure
complements an ENTER at the beginning of the procedure
to simplify stack management and to control access to
variables for nested procedures.
Enter
107
âš« Includes two parameters. The first parameter specifies the
number of bytes of dynamic storage to be allocated on the
stack for the routine being entered. The second parameter
corresponds to the lexical nesting level (0-31) of the
routine.
âš« The specified lexical level determines how many sets of
stack frame pointers the CPU copies into the new stack
frame from the preceding frame.
âš« This list of stack frame pointers is sometimes called the
display.
âš« EX. ENTER 2048,3
108
âš« ESP serves as a starting point for all PUSH and POP
operations within that procedure.
âš« To enable a procedure to address its display, ENTER leaves
EBP pointing to the beginning of the new stack frame.
âš« ENTER provides variable access to next lexical level
procedure through a display that provides addressability to
the calling program's stack frame.
âš« 1.MAIN PROGRAM has variables at fixed locations.
âš« 2.PROCEDUREA can access only the fixed variables of MAIN.
âš« 3.PROCEDUREB can access only the variables of PROCEDUREA and MAIN.
PROCEDUREB cannot access the variables of PROCEDUREC or D.
âš« 4.PROCEDUREC can access only the variables of PROCEDUREA and MAIN.
âš« PROCEDUREC cannot access the variables of PROCEDUREB or D.
âš« 5.PROCEDURED can access the variables of PROCEDUREC,PROCEDUREA,
and MAIN.
PROCEDURED cannot accessthe variables of PROCEDUREB.
109
âš« Procedure A can access variables in MAIN since
MAIN is at level 1. Therefore the base for the
dynamic storage for MAIN is at [EBP-2].
âš« All dynamic variables for MAIN are at a fixed
offset from this value.
110
âš« B can access variables in A and MAIN by
fetching from the display the base addresses of
the respective dynamic storage areas.
111
LEAVE
112
âš« LEAVE (Leave Procedure) reverses the action
of the previous ENTER instruction. The LEAVE
instruction does not include any operands.
âš« LEAVE copies EBP to ESP to release all stack
space allocated to the procedure by the most
recent ENTERinstruction.
âš« Then LEAVE pops the old value of EBPfrom the
stack.
FLAG CONTROL INSTRUCTIONS
Carry and Direction flag control Instructions
113
Flag Control Instruction Effect
STC (Set Carry Flag) CF <- 1
CLC (Clear Carry Flag) CF <- O
CMC (Complement Carry Flag) CF <- NOT (CF)
CLD (Clear Direction Flag) DF <- O
STD (Set Direction Flag) DF <- 1
FLAG CONTROL INSTRUCTIONS
FlagTransfer Instructions
âš« The flag transfer instructions allow a program to alter
the other flag other than CF and DF bits with the bit
manipulation instructions after transferring these flags
to the stack or theAH register.
âš« LAHF (Load AH from Flags) copies SF,ZF,AF,PF,and
CF to AH bits 7,6,4,2,and 0,respectively (see Figure 3-
22).The contents of the remaining bits (5, 3, and1) are
undefined.The flags remain unaffected.
âš« SAHF (StoreAH into Flags) transfers bits 7,6,4,2,and
0 fromAH into S
F
,ZF
,AF
,PF
,and CF
,respectively
114
âš« PUSHF (Push Flags) decrements ESP by two and then
transfers the low-order word of the flags register to the
word at the top of stack pointed to by ESP. The variant
PUSHFD decrements ESP by four, then transfers both
words of the extended flags register to the top of the
stack pointed to by ESP (the VM and RF flags are not
moved,however).
âš« POPF (Pop Flags) transfers specific bits from the word at
the top of stack into the low-order byte of the flag
register,then increments ESPby two.The variant POPFD
transfers specific bits from the doubleword at the top of
the stack into the extended flags register (the RFandVM
flags are not changed,however), then increments ESPby
four.
115
COPROCESSOR INTERFACE INSTRUCTIONS
116
âš« The 80386 also has features to support emulation of the
numeric coprocessor when the coprocessor is absent.
âš« ESC (Escape) : Used by Coprocessor is a 5-bit
sequence that begins the opcodes that identify floating
point numeric instructions.
âš« ESC pattern tells 80386 to send the opcode and addresses
of operands to numeric coprocessor.
âš« The numeric coprocessor uses the escape instructions to
perform high-performance, high-precision floating point
arithmetic.
COPROCESSOR
INTERFACE
INSTRUCTIONS
117
âš« WAIT (Wait)
âš« Suspends (80386) program execution until the
80386 CPU detects that the BUSY pin is inactive.
âš« This condition indicates that the coprocessor has
completed its processing and CPU may obtain
result.
SEGMENT REGISTER INSTRUCTIONS (In Groups)
Segment-register transfer instructions.
MoV ••• ,SegReg
MoV SegReg,•••
PUSH
S
egReg POP
SegReg
Control transfers to another executable segment.:
JMPfar
CALL far
RET far
Data pointer instructions.
LOS
LES
LFS
LGS 118
Data Pointer Instructions
119
âš«LDS (Load Pointer UsingDS)
LDS ESI,STRING_X
The source operand must be a memory operand, and the
destination operand must be a general register. DS receives
the segment-selector of the pointer. The destination register
receives the offset part of the pointer, which points to a
specific location within the segment.
âš«LES(Load Pointer UsingES)
LESEDI,DESTINATION_X
operates identically to LDS except that ESreceives
the segment selector rather than DS.
âš«LFS (Load Pointer Using FS)
Operates identically to LDS except that
FSreceives the segment selector rather
than DS.
âš«LGS (Load Pointer Using GS)
Operates identically to LDS except that GS
receives the segment selector rather than
DS.
âš«LSS (Load Pointer Using SS)
Operates identically to LDS except that
SSreceives the segment selector rather
than DS.
120
Miscellaneous Instructions
121
âš« LEA (Load EffectiveAddress)
Transfers the offset of the source operand (rather than its value) to the
destination operand. The source operand must be a memory operand,
and the destination operand must be a general register. This instruction
is especially useful for initializing registers before the execution of the
string primitives (ESI,EDI)
LEA EBX,EBCDIC_TABLE
âš« NOP (No Operation)
NOP (No Operation) occupies abyte of storage but affects nothing but
the instruction pointer,EIP.
âš« XLAT (Translate)
XLAT (Translate) replaced a byte in the AL register with a byte from a
user-coded translation table. When XLAT is executed, AL should have
the unsigned index to the table addressed by EBX. XLAT changes the
contents ofAL from table index to table entry.EBX is unchanged.
Feedback
122
âš«Teaching Method
âš«Am I audible?
âš«Am I interactive with you?
âš«Study Material (PPT,Notes etc.)
⚫Any Suggestionsare welcome…
Solve
123
âš«Explain 80386Architecture
⚫Write aprocedure for „ASCII to HEX ‟
and„HEX toASCII ‟Conversion.
âš«List and Explain General Purpose Registers.
âš«Explain following flags from EFLAG register
1.VM 2.IOPL 3.RF
âš«Explain following instructions
1.XOR 2.PUSHA 3.CALL 4.JMP
THANKYOU
All THE BEST !!
124

More Related Content

Similar to Microprocessor Unit -1 SE computer-II.pptx

Architecture of 80386(www.munnuz.co.cc)
Architecture of 80386(www.munnuz.co.cc)Architecture of 80386(www.munnuz.co.cc)
Architecture of 80386(www.munnuz.co.cc)muneer.k
 
80386 processor
80386 processor80386 processor
80386 processorRasmi M
 
Module 4 advanced microprocessors
Module 4 advanced microprocessorsModule 4 advanced microprocessors
Module 4 advanced microprocessorsDeepak John
 
The 8086 Micro Processor Architecture By Dr. RidhaJemal
The 8086 Micro Processor Architecture By Dr. RidhaJemalThe 8086 Micro Processor Architecture By Dr. RidhaJemal
The 8086 Micro Processor Architecture By Dr. RidhaJemalAnas Sa
 
Microprocessor 80386
Microprocessor 80386Microprocessor 80386
Microprocessor 80386yash sawarkar
 
Microprocessor
MicroprocessorMicroprocessor
MicroprocessorCharltonInao1
 
BE_6_SEM_EE_MP_MC-_COMP._OF_8086_FAMILY-AMIT_THAKUR-converted-converted.pdf
BE_6_SEM_EE_MP_MC-_COMP._OF_8086_FAMILY-AMIT_THAKUR-converted-converted.pdfBE_6_SEM_EE_MP_MC-_COMP._OF_8086_FAMILY-AMIT_THAKUR-converted-converted.pdf
BE_6_SEM_EE_MP_MC-_COMP._OF_8086_FAMILY-AMIT_THAKUR-converted-converted.pdfJaimin Jani
 
Introduction to 80386 microprocessor
Introduction to 80386 microprocessorIntroduction to 80386 microprocessor
Introduction to 80386 microprocessorShehrevar Davierwala
 
80386 microprocessor
80386 microprocessor80386 microprocessor
80386 microprocessorJerin Sebastian
 
Cs14 406 80386-mod1
Cs14 406 80386-mod1Cs14 406 80386-mod1
Cs14 406 80386-mod1Akhila Rahul
 
80386 Architecture
80386 Architecture80386 Architecture
80386 ArchitectureRohit Choudhury
 

Similar to Microprocessor Unit -1 SE computer-II.pptx (20)

Mpmc
MpmcMpmc
Mpmc
 
Architecture of 80386(www.munnuz.co.cc)
Architecture of 80386(www.munnuz.co.cc)Architecture of 80386(www.munnuz.co.cc)
Architecture of 80386(www.munnuz.co.cc)
 
Introduction to 80386
Introduction to 80386Introduction to 80386
Introduction to 80386
 
80386 processor
80386 processor80386 processor
80386 processor
 
Module 4 advanced microprocessors
Module 4 advanced microprocessorsModule 4 advanced microprocessors
Module 4 advanced microprocessors
 
The 8086 Micro Processor Architecture By Dr. RidhaJemal
The 8086 Micro Processor Architecture By Dr. RidhaJemalThe 8086 Micro Processor Architecture By Dr. RidhaJemal
The 8086 Micro Processor Architecture By Dr. RidhaJemal
 
It322 intro 2
It322 intro 2It322 intro 2
It322 intro 2
 
Microprocessor 80386
Microprocessor 80386Microprocessor 80386
Microprocessor 80386
 
80386
8038680386
80386
 
Pentium
PentiumPentium
Pentium
 
Pentium
PentiumPentium
Pentium
 
80386.pptx
80386.pptx80386.pptx
80386.pptx
 
Advanced microprocessor
Advanced microprocessorAdvanced microprocessor
Advanced microprocessor
 
Processoer 80486
Processoer 80486Processoer 80486
Processoer 80486
 
Microprocessor
MicroprocessorMicroprocessor
Microprocessor
 
BE_6_SEM_EE_MP_MC-_COMP._OF_8086_FAMILY-AMIT_THAKUR-converted-converted.pdf
BE_6_SEM_EE_MP_MC-_COMP._OF_8086_FAMILY-AMIT_THAKUR-converted-converted.pdfBE_6_SEM_EE_MP_MC-_COMP._OF_8086_FAMILY-AMIT_THAKUR-converted-converted.pdf
BE_6_SEM_EE_MP_MC-_COMP._OF_8086_FAMILY-AMIT_THAKUR-converted-converted.pdf
 
Introduction to 80386 microprocessor
Introduction to 80386 microprocessorIntroduction to 80386 microprocessor
Introduction to 80386 microprocessor
 
80386 microprocessor
80386 microprocessor80386 microprocessor
80386 microprocessor
 
Cs14 406 80386-mod1
Cs14 406 80386-mod1Cs14 406 80386-mod1
Cs14 406 80386-mod1
 
80386 Architecture
80386 Architecture80386 Architecture
80386 Architecture
 

Recently uploaded

What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2RajaP95
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and usesDevarapalliHaritha
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 

Recently uploaded (20)

What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and uses
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 

Microprocessor Unit -1 SE computer-II.pptx

  • 1. 80386DX-Basic Programming Model andApplications Instruction Set Prof.Pratima Kadam Assistant Professor Computer Engineering Department 1
  • 2. Course Objectives: o To learn the architecture andprogrammer„s model of advanced processor. o To understand the system level features and processes of advanced processor . o To acquaint the learner with application instruction set and logic to build assembly language programs. o To understand debugging and testing techniques confined to 80386 DX. Course Outcomes: • On completion of the course,student will be able to– • Apply the assemblylanguageprogramming to develop smallreal life embedded application. • Understand the architecture of the advanced processor thoroughly to use the resources for programming. • Understand the higher processor architectures descended from 80386 architecture . 2
  • 3. What is Microprocessor 3 âš« A microprocessor, sometimes called a logic chip, is a computer processor on a microchip. âš« It is also called as “Heart of Computer.” âš« The microprocessor contains all, or most of, the central processing unit (CPU) functions. âš« A microprocessor is designed to perform arithmetic and logic operations that make use of small number-holding areas called registers.
  • 4. âš«Typical microprocessor operations include adding, subtracting, comparing two numbers, and fetching numbers from one area to another. âš«These operations are the result of a set of instructions that are part of the microprocessor design. 4
  • 5. Three basic characteristics differentiate microprocessors: 5 âš« Instruction set: The set of instructions that the microprocessor can execute. âš« Bandwidth : The number of bits processed in a single instruction. âš« Clock speed : Given in megahertz (MHz), the clock speed determines how many instructions per second the processor can execute. In both cases, the higher the value, the more powerful the CPU. For example, a 32-bit microprocessor that runs at 50MHz is more powerful than a 16-bit microprocessor that runs at 25MHz.
  • 8. âš«8086 can be work in two modes âš« Minimum Mode:For single processor systems. âš« Maximum Mode:For system with two or more processors. âš«Depending upon modes signals can be divided into âš« Signals having common functions in both modes âš« Signals for Minimum Mode âš« Signals for Maximum Mode 8
  • 9. Logical to physical address Translation in 8086 9 âš« The 20-bit address of a byte is called its PhysicalAddress. âš« But,it is specified as a LogicalAddress. âš« Logical address is in the form of: âš« BaseAddress :Offset the memory âš« Offset location is the displacement of from the starting location of the segment.
  • 10. Example 10 âš«The value of Data Segment Register (DS) is 2222 H. âš«To convert this 16-bit address into 20-bit, the BIU appends 0H to the LSBsof the address. âš«After appending, the starting address of the Data Segment becomes 22220H. âš«If the data at any location has a logical address specified as: âš« 2222 H :0016 H âš«Then, the number 0016 H is the offset. 2222 H is the value of DS.
  • 11. To calculate the physical address of the memory, BIU uses the following formula: PhysicalAddress = StartingAddress of Segment + Offset To find the starting address of the segment, BIU appends the contents of Segment Register with 0H. Then,it adds offset to it. Therefore: EA = 22220 H + 0016 H ------------ 22236 H 11
  • 12. 12
  • 13. New in 80386 13 âš«Data bus = 32bit,all registers of 32 bit and Eflags is also of 32 bit. âš«Address Bus = 32 bit.(4 GB Memory) âš«Enhanced Memory Management Unit. âš«Supports Virtual addressing. âš«Faster execution of arithmetic operations. âš«Works in :- âš«1.Real Mode (8086) âš«2.Protected Mode âš«3.Virtual Mode âš«Additional Interrupts in IVT.
  • 14. FEATURES 14 âš« Manufactured using Intel‟s complementary High- performance Metal-oxide-semiconductor 3 process. âš« 8 general purpose registers of 32-bit . âš« 32-bit Address and Data Bus. âš« Supports 8 bit,16 bit,32 bit data. âš« Prefetch queue of 16B. âš« Very Large address space i.e VM of 64 TB and PM of 4GB. âš« Supports Segmentation and Paging.
  • 15. âš« 4 levels of protection. âš« Uses 3-stage pipelines. âš« Supports multitasking with protection. âš« On chip cache memory for TLB. âš« Pipelined instruction Execution. âš« Memory Management unit. âš« High speed numeric support via 80287 and 80387 coprocessor. âš« It can operate in real , protected and virtual mode. 15
  • 16. Family tree of 80386 16 Chip Introduction Data bus Addres s Bus Memory 4004 1971 4 8 256 Byte 8008 1972 8 8 256 Byte 8080 1974 8 16 64 KB 8086/88 1978 16/8 20 1M 80186/188 1982 16/8 20 1M 80286 1983 16 24 16M:Clock speed is high 80386 DX(1986:not compatibility) SX(1988: mostly used, Not Co- Processor) DX:32+132 pin SX:16+100 pin 32 24 DX:4G (275,000 transistor ) SX:16MB 80486 32 32 Memory Size: 4G +16K cache
  • 17. Difference between 80386 SX/DX 8-bit and 16-bit 17 •Both have the same internal architecture. •Lower cost package and the ease of interfacing to memory and peripherals make , •SX suitable for use in low cost systems.
  • 18. Introduction to 80386 18 o The 80386 is an advanced 32-bit microprocessor optimized for multitasking operating systems and designed for applications needing very high performance. o The 32-bit registers and data paths support 32-bit addresses and data types. o The processor can address up to 4 gigabytes of physical memory and 64 terabytes (246 bytes) of virtual memory. o The on-chip memory management facilities include address translation registers, advanced multitasking hardware, a protection mechanism, and paged virtual memory. o Special debugging registers provide data and code breakpoints even in ROM-based software.
  • 19. Features of 80386 19 â–Ł The 80386 has three processingmodes: â–Ł 1.Protected Mode: o Protected mode is the natural 32-bit environment of the 80386 processor. o In this mode all instructions and features are available. â–Ł 2.Real-Address Mode. o Real-address mode is the mode of the processor immediate after RESET. o In real mode the 80386 appears to programmers as afast 8086 with some new instructions. o Most applications of the 80386 will use real mode. â–Ł 3.Virtual 8086 Mode: o Virtual 8086 mode is a dynamic mode which can switch repeatedly and rapidly betweenV86 mode and protected mode. o The CPU entersV86 mode from protected then leavesV86 mode and enters protected.
  • 21. Architecture of 80386 21 âš« The Internal Architecture of 80386 is divided into 3 sections: â—¦ i) Central processing unit (CPU) đźž„Execution unit (EU) and đźž„Instruction unit (IU) â—¦ ii) Memory management unit (MMU) đźž„Segmentation unit đźž„ Paging unit. â—¦ iii) Bus interface unit( BIU)
  • 22. Central Processing Unit 22 âš« Central processing unit is further divided into Execution unit and Instruction unit. • Execution unit has 8 General purpose and 8 Special purpose registers which are either used for handling data or calculating offset addresses. âš« The Instruction unit decodes the opcode bytes received from the 16-byte instruction code queue and arranges them in a 3- instruction decoded instruction queue.
  • 23. âš«After decoding them pass it to the control section for deriving the necessary control signals. The barrel shifter increases the speed of all shift and rotate operations. • The multiply / divide logic implements the bit-shift-rotate algorithms to complete the operations in minimum time. • Even 32- bit multiplications can be executed within one microsecond by the multiply / divide logic. 23
  • 24. Memory Management Unit 24 âš«The Memory management unit consists of a Segmentation unit and a Paging unit. âš«Segmentation unit allows the use of two address components, viz. segment and offset for relocability and sharing of code and data. âš«Segmentation unit allows segments of size 4Gbytes at max.
  • 25. âš«The Paging unit organizes the physical memory in terms of pages of 4 kbytes size each. âš«Paging unit works under the control of the segmentation unit, i.e. each segment is further divided into pages. âš«The virtual memory is also organizes in terms of segments and pages by the memory management unit. 25
  • 26. âš« The Segmentation unit provides a 4 level protection mechanism for protecting and isolating the system code and data from those of the application program. âš« Paging unit converts linear addresses into physical addresses. âš« The control and attribute PLA checks the privileges at the page level. Each of the pages maintains the paging information of the task. âš« The limit and attribute PLA checks segment limits and attributes at segment level to avoid invalid accesses to code and data in the memory segments. 26
  • 27. Bus Interface Unit 27 âš« The Bus control unit has a prioritizer to resolve the priority of the various bus requests. âš« This controls the access of the bus. The address driver drives the bus enable and address signal A0– A31. âš« The pipeline and dynamic bus sizing unit handle the related control signals. âš« The data buffers interface the internal data bus with the system bus.
  • 28. MEMORY ORGAN IZATION AND SEGMENTATION 28 âš« The physical memory of an 80386 system is organized as a sequence of 8-bit bytes. âš« Each byte is assigned a unique address that ranges from 0 to amaximum of 232 -1.(4 Gigabytes). âš« The model of memory organization determined by systems-software designers. âš« Two model of memory âš« 1.Flat model:single array of up to 4 GB. âš« A pointer into this flat address space is a32-bit ordinal number that may range from 0 to 232 -1.
  • 29. MEMORY ORGAN IZATION AND SEGMENTATION 29 linear âš« Segmented model: collection of up to 16,383 address spaces. âš« Viewed by an applications program (called the logical address space) âš« The processor maps the 64 terabyte logical address space onto the physical address space (4 GB) by the address translation mechanisms. âš« Each of these linear subspaces is called asegment. âš« A segment is aunit of contiguous address space âš« Segment sizes may range from 1 byte up to a maximum of 232 bytes (4 gigabytes). âš«
  • 30. MEMORY ORGAN IZATION AND SEGMENTATION âš« A complete pointer in this address space consists of two parts. âš« l. A segmentselector ,which isa16-bit field that identifies a segment. âš« 2. An offset,which is a32-bit ordinal that addresses to the byte level within asegment. 30
  • 31. DataTypes: 31 âš« Bytes, words, and doublewords are the fundamental data types âš« Integer: A signed binary numeric value contained in a 32- bit doubleword,16-bit word, or 8-bit byte. All operations assume a2's complement representation. - range of an 8-bit integer is -128 through +127 - 16-bit integers may range from -32,768 through +32,767 - 32-bit integers may range from -231 through +231-1
  • 32. Execution unit :DATA TYPES âš« Fundamental data types: 32
  • 33. âš« Ordinal: An unsigned binary numeric value contained in a32-bit doubleword, 16-bit word, or 8-bit byte. All bits are considered in determining magnitude of the number. - range of an 8-bit ordinal number is 0-255; - 16 bits can represent values from 0 through 65,535; - 32 bits can represent values from 0 through 232-1. âš« Near Pointer:A 32-bit logical address.A near pointer is an offset within asegment. âš« Far Pointer:A 48-bit logical address of two components:a16-bit segment selector component and a32-bit offset component. âš« String: A contiguous sequenceof bytes, words, or doublewords.A string may contain from zero bytes to 232-1 bytes (4 gigabytes). 33
  • 34. âš« Bit field: A contiguous sequence of bits. A bit field may begin at any bit position of any byte and may contain up to 32 bits. âš« Bit string: A contiguous sequence of bits.A bit string may begin at any bit position of any byte and may contain up to 232-1 bits. âš« BCD: A byte (unpacked) representation of adecimal digit in the range0 through 9. Unpacked decimal numbers are stored as unsigned byte quantities. One digit is stored in each byte. âš« Packed BCD: A byte (packed) representation of two decimal digits, each in the range 0 through 9. One digit is stored in each half-byte. 34
  • 35. MEMORY ORGA N IZATION AND SEGMENTATION âš« . 35
  • 36. Registers 36 The 80386 has eight 32-bit general purpose registers which may be used as either 8 bit, 16 bit or 32 bit registers. •A 32-bit register known as an extended register, is represented by the register name with prefix E. •Example :A32 bit register corresponding to AX is EAX •So the general purpose registers of 386 are EAX, EBX, ECX, EDX, EBP, ESP, ESI and EDI
  • 37. Registers 37 âš« BP, SP, SI, DI represents the lower 16 bit of their 32 bit counterparts, and can be used as independent 16 bit registers. âš« The 16 bit flag register is available along with 32 bit counterpart EFLAGS.
  • 38. Register Set 38 âš«The 80386 contain total 16 registers These registers grouped as: 1. General 2. Segment 3. Status and Instruction 4. Control Registers 5. SystemAddress Registers 6. Debug Registers 7. Test Registers
  • 41. SEGMENT REGISTERS o Six segments of memory may be immediately accessible to an executing 80386 program. o The segment registers CS, DS, SS, ES, FS, and GS are used to identify these six current segments. o Each of these registers specifies a particular kind of segment, as characterized by the associated mnemonics ("code," "data," or "stack"). 41
  • 42. CS Register âš«CS: The segment containing the currently executing sequence of instructions is known as the current code segment. âš« The 80386 fetches all instructions from this code segment, using as an offset the contents of the instruction pointer. 42
  • 43. S Sand ES,DS,FS,GSRegister 43 âš« SS:Subroutine calls, parameters, andprocedure activation records usually require to allocate memory as astack. âš« All stack operations use the S S register to locate the stack. âš« Data Registers: The DS, ES, FS, and GS registers allow the specification of four data segments. âš« Access different types of data structures; âš« Types of data structures: âš« Current module, Exported data, Dynamically created data structure and data Shared with another task.
  • 45. Flag Register âš« The Flag register of 80386 is a32 bit register. âš« Out of the 32 bits,Intel has reserved bits D18 to D31,D5 and D3 and set to 0 âš« While D1 is always set at 1. âš« Twoextra new flagsareaddedto the 80286flagto derive the flag register of 80386. âš« They areVM and RFflags. 45
  • 47. VM Bit - Virtual Mode Flag 47 âš« If this flag is set toVM=1,the 80386 enters the virtual 8086 mode within the protection mode. âš« WhenVM bit is 0,386 operates in protected mode âš« This is to be set only when the 80386 is in protected mode. âš« This bit can be set using IRET instruction or any task switch operation only in the protected mode.
  • 48. RF-Bit Resume Flag 48 âš« If RF=1, 386 ignores debug faults and does not take another exception so that an instruction can be restarted after anormal debug exception. âš« If RF=0, 386 takes another debug exception to service debug faults âš« This flag is used with the debug register breakpoints. âš« It is checked at the starting of every instruction cycle and if it is set=1, any debug fault is ignored during the instruction cycle. âš« The RF is automatically reset after successful execution of every instruction, except for IRET and POPF instructions
  • 49. RF- Resume Flag... 49 âš« Also, it is not automatically cleared after the successful execution of JMP,CALL and INT instruction causing a task switch.
  • 50. âš«VM (Virtual 8086 Mode): If set while the Intel386 DX is in Protected Mode, the Intel386 DX will switch to Virtual 8086 operation. âš«The VM bit can be set only in Protected Mode, by the IRET instruction (if current privilege level e 0) âš«RF (Resume Flag): The RF flag is used in conjunction with the debug register breakpoints. âš«When RFis set, it causes any debugfault to be ignored on the next instruction. 50
  • 51. âš«NT (Nested Task): This flag applies to Protected Mode. âš«NT is set to indicate that the execution of this task is nested within another task âš«The value of NT in EFLAGS is tested by the IRET instruction to determine whether to do an inter-task return or an intra-task return. 51
  • 52. IOPL (Input / Output Privilege Level) 52 âš«This two-bit field applies to Protected Mode. IOPL indicates the numerically maximum CPL(current privilege level) value permitted to execute I/O instructions without generating an Exception âš«It also indicates the maximum CPL value allowing alteration of the IF (INTR Enable Flag) bit when new values are popped into the EFLAG register
  • 53. âš«IF (INTR Enable Flag): The IF flag, when set, allows recognition of external interrupts signaled on the INTR pin. âš«TF (Trap Enable Flag): When TF is set, the Intel386 DX generates an exception 1 trap after the next instruction is executed. âš«When TF is reset, exception 1 traps occur only as a function of the breakpoint addresses loaded into debug registers DR0- DR3. 53
  • 54. âš«OF (Overflow 54 Flag) : It is set if the operation resulted in a signed overflow. Signed overflow occurs when the operation resulted in carry/borrow into the sign bit (high-order bit) of the result. âš«DF (Direction Flag) : DF defines whether ESI and/or EDI registers post-decrement or post-increment during the string instructions. âš«Post-decrement occurs if DF is set
  • 55. Flags 55 âš«The arithmetic instructions use CF, SF, ZF, AF ,PF ,CF âš«The control flag DF controls “STRING” instruction âš«Clearing DF flag causes string instructions to auto increment or to process string from low to high address
  • 56. Hidden Registers/ Program invisible registers/ Special Registers 56
  • 57. Control Registers 57 âš« The 80386 has four 32 bit control registers CR0, CR1,CR2 and CR3 to hold global machine status. âš« CR1 is not used in 386 and reserved for future use. âš« Load and store instructions are available to access these registers.
  • 59. SystemAddress Registers 59 âš« The 386 supports 4 types of descriptor table: • Global descriptor table (GDT), • Local descriptor table (LDT), • Interrupt descriptor table (IDT) • Task state segment descriptor (TSS). âš« Four special registers are defined to hold the base address of these tables • Global descriptor table Register (GDTR) • Local descriptor table Register (LDTR) • Interrupt descriptor table Register (IDTR) • Task state segment descriptor Register (TR).
  • 60. Debug Registers 60 âš« Intel has provided a set of 8 debug registers for hardware debugging. âš« DR4 and DR5 are Intel reserved. âš« The initial four registers DR0 to DR3 store four program controllable breakpoint addresses, âš« DR6 and DR7 respectively hold breakpoint status and breakpoint control information.
  • 61. Debug Registers 61 DR7 DR6 DR5 DR4 DR3 DR2 DR1 DR0 breakpoint control info breakpoint status RESERVED RESERVED Linear breakpoint address 3 Linear breakpoint address 2 Linear breakpoint address 1 Linear breakpoint address 0 31 0
  • 62. Test Registers 62 âš«Two test register are provided by 80386 for page caching namely test control and test status register.
  • 63. INSTRUCTION FORMAT âš« The information encoded in an 80386 instruction includes aspecification of ; âš« Operation to be performed (Opcode). âš« Type of the operands to be manipulated, âš« Location of these operands. Opcode Source(M/ Reg) Destination(M/ Reg) 63
  • 64. Operand Selection 64 âš« In the instruction itself(immediate operand) âš« In aregister âš« In memory âš« At an I/O port âš« Implicit operand âš« Explicit operand âš« Implicit and Explicit Operand
  • 65. INSTRUCTION FORMAT 65 âš« Two-operand instructions of the 80386 permit operations of the following kinds: âš« • Register-to-register âš« • Register-to-memory âš« • Memory-to-register âš« • Immediate-to-register âš« • Immediate-to-memory âš« Certain string instructions and stack manipulation instructions transfer data from memory to memory. âš« Push and pop stack operations allow transfer between memory operands and the memory-based stack.
  • 68. EffectiveAddress Computation… 68 âš« Displacement: Indicates the offset of the operand . Used to directly address a statically allocated scalar operand. âš« Base: Offset is specified indirectly in one of the general registers,as for based variables. âš« Base+displacement: âš« To index into static array when element size is not 2,4,8 bytes. âš« Access item of record. Displacement component locates an item within record. âš« (Index*scale) + displacement: Provides efficient indexing into a static array when element size is 2,4,8 bytes.
  • 69. EffectiveAddress Computation… 69 âš« Base + Index + Displacement: Two registers used together support either a two dimensional array (where displacement determine beginning of array) or one of several instances of an array of records (where displacement indicates an item in the record.) âš« Base + (Index * Scale) + displacement: This combination provides efficient indexing of a two-dimensional array when element of the array are 2,4,8 bytes wide.
  • 70. Interrupts and Exceptions 70 program âš« Two mechanism for interrupting execution âš« Exceptions are synchronous events that are the responses of the CPU to certain conditions detected during the execution of an instruction. âš« Interrupts are asynchronous events typically triggered by external devices needing attention.
  • 72. APPLICATIONS INSTRUCTION SET âš«To write application software for the 80386 executing in protected virtual-address mode. âš«DATA MOVEMENT INSTRUCTIONS âš«They fall into the following classes: âš«1. General-purpose data movement instructions. âš«2.Stack manipulation instructions. âš«3.Type-conversion instructions. 72
  • 73. General-Purpose Data Movement Instructions 73 âš« MOV (Move) transfers a byte, word, or double word from the source operand to the destination operand. âš« The MOV instruction is useful for transferring data along any of these paths âš« •To aregister from memory âš« •To memory from aregister âš« • Between general registers âš« • Immediate data to aregister âš« • Immediate data to amemory âš« XCHG (Exchange) swaps the contents of two operands.
  • 74. Stack Manipulation Instructions 74 âš« PUSH (Push) decrements the stack pointer (ESP), then transfers the source operand to the top of stack indicated by ESP âš« PUSH is often used to place parameters on the stack before calling aprocedure. âš« The PUSH instruction operates on memory operands, immediate operands,and register . âš« PUSHA (Push All Registers) saves the contents of the eight general registers on the stack.. âš« The processor pushesthe general registers on the stack in the following order: âš« EAX, ECX, EDX, EBX, the initial value of ESPbefore EAX was pushed,EBP ,ESI,and EDI.
  • 75. Type Conversion Instructions 75 âš« The type conversion instructions convert bytes into words, words into double words, and double words into 64-bit items (quad-words). âš« CWD,CDQ,CBW,and CWDE âš« CWD (ConvertWord to Doubleword) âš« CBW (Convert Byte to Word) âš« CDQ (Convert Doubleword to Quad-Word) âš« CWDE (Convert Word to Doubleword Extended) âš« MOVSX (Move with Sign Extension) âš« MOVZX (Move with Zero Extension)
  • 76. BINAR YARITHMETIC INSTRUCTIONS ** Addition and Subtraction Instructions 76 âš« ADD D ,S (sets CF is there is carry) âš« ADC D ,S (D= D+S+C) âš« INC D (Increment Byte,Word or Doubleword by 1) âš« SUB D ,S (sets CF is there is borrow) âš« SBBD ,S (D= D-S-C) âš« DEC D (Decrement Byte,Word or Doubleword by 1)
  • 77. BINAR YARITHMETIC INSTRUCTIONS ** Comparison and Sign Change Instructions 77 âš«CMP D,S (Destination-Source) Updates OF ,S F ,ZF ,AF ,PFand CF âš«NEG D Subtracts asigned integer operand from zero
  • 78. BINAR YARITHMETIC INSTRUCTIONS ** Multiplication and Divide Instructions 78 âš«MUL S âš«IMUL S âš«DIV S (Unsigned Integer Multiply) (Signed Integer Multiply) (Unsigned Integer Divide) Dividend Quotient Remainder AX AL AH DX:AX AX DX EDX:EAX EAX EDX âš«IDIV S (Signed Integer Divide) Uses same registers as in DIV
  • 79. DECIMAL ARITHMETIC INSTRUCTIONS 79 âš« Decimal Arithmetic is performed by combining the binary arithmetic instructions with decimal arithmetic instructions. âš« Decimal Arithmetic instructions are used in one of the following ways - To adjust the results of a previous binary arithmetic operation to produce a valid packed or unpacked decimal result. - To adjust the inputs to a subsequent binary arithmetic operation so that the operation will produce a valid packed or unpacked decimal result. âš« These instructions operate only on the AL or AH registers. Most utilize the AF flag.
  • 80. DECIMAL ARITHMETIC INSTRUCTIONS ** Packed BCDAdjustment Instructions 80 âš« DAA (DecimalAdjust afterAddition) - Adjusts the result of adding two valid packed decimal operands in AL. output - DAA instruction gives us correct decimal instead of hexadecimal. - Carry flag is set if carry was needed. âš« DAS (DecimalAdjust after Subtraction) - Adjusts the result of Subtracting two valid packed decimal operands inAL. - DAS instruction gives us correct decimal output instead of hexadecimal. - Carry flag is set if borrow was needed.
  • 81. DECIMAL ARITHMETIC INSTRUCTIONS ** Unpacked BCDAdjustment Instructions 81 âš« AAA (AsciiAdjustAfterAddition) - AL contain valid unpacked decimal number andAH=00 - AAA must always follow addition of two unpacked decimal operands in AL. - Carry flag is set and AH is incremented if a carry is necessary. âš« AAS (AsciiAdjustAfter Subtraction) - AL contain valid unpacked decimal number andAH=00 - AAS must always follow Subtraction of one unpacked decimal operands from another inAL. - Carry flagis set andAH is incremented if aborrow is necessary.
  • 82. DECIMAL ARITHMETIC INSTRUCTIONS ** Unpacked BCDAdjustment Instructions 82 âš« AAM (AsciiAdjustAfter Multiplication) - Corrects multiplication of two unpacked decimal number. - The high order digit is left in AH, the low order digit in AL. âš« A A D (AsciiAdjustAfter Division) - Modifies numerator in AH and AL for unpacked decimal operands divide operation. - Quotient produced will be valid unpacked decimal. - The high order digit is left in AH, the low order digit in AL. - Adjusts the result in AL and makeAH=00
  • 83. LOGICAL INSTRUCTIONS 83 ⦿ The group of logical instructionsincludes: • The Boolean operation instructions • Bit test and modify instructions • Bit scan instructions • Rotate and shift instructions • Byte set on condition
  • 84. The Boolean operation instructions 84 ⦿ NOT (Not) Inverts the bits in the specified operand to form aone‟s complement of the operand. Has no effect on flags. ⦿ AND,OR, and XOR AND- is useful instruction for turning aparticular bit off. (Turn to 0) OR- isuseful instruction for setting aparticular bit on. (Turn to 1) XOR- is useful instruction for clearing aregister.Or useful for toggling particular bit without changing other bits.
  • 85. Bit test and modify instructions âš« This group of instructions operates on asingle bit which can be in memory or in ageneral register. âš« These instructions first assignthe value of the selected bit to CF ,the carry flag. âš« Then a new value is assigned to the selected bit, as determined by the operation. 85
  • 86. Bit scan instructions 86 âš« These instructions scan a word or doubleword for a one-bit and store the index of the first set bit into a register. âš« The bit string being scanned may be either in a register or in memory. âš« Affects ZF=1 if word is zero,otherwise clear ZF âš« BSF (Bit Scan Forward) scans from low-order to high-order (starting from bit index zero). âš« BSR (Bit Scan Reverse) scans from high-order to low-order (starting from bit index 15 of a word or index 31 of a doubleword).
  • 87. Shift and Rotate Instructions 87 âš«These instructions fall into the following classes: • Shift instructions • Double shift instructions • Rotate instructions
  • 88. SHIFT INSTRUCTIONS 88 âš« The bits in bytes,words, and double words may be shifted arithmetically or logically. âš« CF always contains the value of the last bit shifted out of the destination operand. âš« OF is set if the value of the high-order (sign) bit was changed by the operation. âš« SAL (Shift Arithmetic Left) âš« SHL (Shift Logical Left) âš« SHR (Shift Logical Right) âš« SAR (Shift Arithmetic Right) âš« ROL (Rotate Left) âš« ROR (Rotate Right) âš« RCL (RotateThrough Carry Left)
  • 89. SAL/SHL ⦿ SAL (Shift Arithmetic Left) shifts the destination byte, word, or double word operand left by one or by the number of bits specified in the count operand ⦿ The processor shifts zeros in from the right (low-order) side of the operand as bits exit from the left (high-order) side. ⦿ Sal AX,CL 89
  • 90. SHR (Shift Logical Right) 90
  • 91. SAR (Shift Arithmetic Right) âš« The processor preserves the sign of the operand by shifting in 0 on the left (high-order) side if the value is positive âš« or by shifting by 1 if the value is negative. âš« SAR is rounded toward negative infinity 91
  • 92. DOUBLE-SHIFT INSTRUCTIONS âš« These instructions provide the basic operations needed to implement operations on long unaligned bit strings. âš« The double shifts operate either on word or double word operands,as follows: âš« SHLD (Shift Left Double) :shifts bits of the R/M field to the left, while shifting high-order bits from the Reg field into the R/M field on the right. âš« The result is stored back into the R/M operand. âš« The Regfield is not modified. 92
  • 93. SHRD (Shift Right Double) shifts bits of the R/M field to the right, while shifting low-order bits from the Reg field into the R/M field on the left 93
  • 94. ROTATE INSTRUCTIONS 94 âš« Rotate instructions allow bits in bytes, words, and double words to be rotated. âš« Bits rotated out of an operand are not lost as in a shift, but are "circled" back into the other "end" of the operand. âš« Rotates affect only the carry and overflow flags. âš« CF may act as an extension of the operand. âš« CF always contains the value of the last bit rotated out.
  • 95. ROL and ROR âš« ROL (Rotate Left) rotates the byte, word, or double word destination operand left by one or by the number of bits specified in the count operand . âš«ROR(Rotate Right) 95
  • 96. RCL and RCR âš« It treats CF as a high-order one-bit extension of the destination operand. 96
  • 97. CONTROLTRANSFERINSTRUCTIONS 97 âš« UnconditionalTransfer Instructions: âš« JMP- JMP is a one-way transfer of execution; it does not save areturn address on the stack. âš« CALL- activates an out-of-line procedure, saving on the stack the address of the instruction following the CALL for later use by aRET (Return) instruction.***stack âš« RET- terminates the execution of aprocedure and transfers control through aback-link on the stack to the program that originally invoked the procedure.*** back link on the stack EIP âš« IRET- returns control to an interrupted procedure. IRET differs from RETin that it also popsthe flagsfrom the stack into the flags register.
  • 99. Conditional 99 âš« LOOP âš« LOOPE (Loop While Equal) and LOOPZ (Loop While Zero) These instructions automatically decrement the ECX register before testing ECX and ZF for the branch conditions. ECX=0 and ZF=0 ignore âš« LOOPNE (Loop While Not Equal) and LOOPNZ (Loop While Not Zero) ECX=0 and ZF=1 ignore âš« JCXZ (Jump if ECX Zero) branches to the label specified in the instruction if it finds avalue of zero in ECX.
  • 100. Software Generated Interrupts 100 âš« INT n (Software Interrupt) activates the interrupt service routine that corresponds to the number coded within the instruction. The interrupt service routine terminates with an IRET instruction that returns control to the instruction that follows INT. âš« INTO (Interrupt on Overflow) invokes interrupt 4 if OF is set. âš« BO U ND (Detect Value Out of Range) verifies that the signed value contained in the specified register lies within specified limits. An interrupt (INT 5) occurs if the value contained in the register is less than the lower bound or greater than the upper bound.
  • 101. STRINGAND CHARACTERTRANSLATION INSTRUCTIONS 101 ⦿ 1. A set of primitive string operations âš« MOVS — Move String âš« CMPS — Compare string âš« SCAS — Scan string âš« LODS — Load string âš« STOS — Store string ⦿ 2. Indirect, indexed addressing, with automatic incrementing or decrementing of the indexes. Indexes: âš« ESI —- Source index register âš« EDI — Destination index register âš« Control flag: âš« DF — Direction flag âš« Control flag instructions: âš« CLD Clear direction flag instruction âš« STD — Set direction flag instruction ⦿ 3. Repeat prefixes âš« REP Repeat while ECX not zero âš« REPE/REPZ Repeat while equal or zero âš« REPNE/REPNZ Repeat while not equal or not zero
  • 103. Indexing and Direction flag Control 103 âš« The addresses of the operands of string primitives are determined by the ESIand EDI registers. âš« ESI points to source operands. By default, ESI refers to a location in the segment indicated by the DS segment register. A segment-override prefix may be used, however, to cause ESIto refer to CS,SS,ES,FS,or GS. âš« EDI points to destination operands in the segment they are indicated by ES;no segment override is possible. âš« The direction flag determines whether incremented or decremented.
  • 104. String Instructions 104 âš« MOVS (Move String) moves the string element pointed to by ESI to the location pointed to by EDI. The MOVS instruction, when accompanied by the REP prefix, operates as a memory-to-memory block transfer.MOVSB,MOVSW,MOVSD âš« CMPS (Compare Strings) subtracts the destination string element (at ES:EDI) from the source string element (at ESI) and updates the flags AF, SF,PF,CF and OF. If the string elements are equal, ZF=1; otherwise, ZF=0. CMPSB compares bytes, CMPSW compares words, and CMPSD compares doublewords. âš« SCAS (Scan String) subtracts the destination string element at ES:EDI from EAX, AX, or AL and updates the flags AF, SF,ZF, PF,CF and OF.If values are equal,ZF=1;otherwise,ZF=0.
  • 105. âš« LODS (Load String) places the source string element at ESI into EAX for doubleword strings, into AX for word strings, or into AL for byte strings.LODS increments or decrements ESIaccording to DF . âš« STOS (Store String) places the source string element from EAX, AX, or AL into the string at ES:DSI. STOS increments or decrements EDI according to DF. 105
  • 106. Instructions for Block Structured Languages 106 âš« Instructions in this section provide machine-language support for functions normally found in high-level languages. âš« ENTER: creates a stack frame that may be used to implement the scope rules of block structured high-level languages. âš« LEAVE: A LEAVE instruction at the end of a procedure complements an ENTER at the beginning of the procedure to simplify stack management and to control access to variables for nested procedures.
  • 107. Enter 107 âš« Includes two parameters. The first parameter specifies the number of bytes of dynamic storage to be allocated on the stack for the routine being entered. The second parameter corresponds to the lexical nesting level (0-31) of the routine. âš« The specified lexical level determines how many sets of stack frame pointers the CPU copies into the new stack frame from the preceding frame. âš« This list of stack frame pointers is sometimes called the display. âš« EX. ENTER 2048,3
  • 108. 108
  • 109. âš« ESP serves as a starting point for all PUSH and POP operations within that procedure. âš« To enable a procedure to address its display, ENTER leaves EBP pointing to the beginning of the new stack frame. âš« ENTER provides variable access to next lexical level procedure through a display that provides addressability to the calling program's stack frame. âš« 1.MAIN PROGRAM has variables at fixed locations. âš« 2.PROCEDUREA can access only the fixed variables of MAIN. âš« 3.PROCEDUREB can access only the variables of PROCEDUREA and MAIN. PROCEDUREB cannot access the variables of PROCEDUREC or D. âš« 4.PROCEDUREC can access only the variables of PROCEDUREA and MAIN. âš« PROCEDUREC cannot access the variables of PROCEDUREB or D. âš« 5.PROCEDURED can access the variables of PROCEDUREC,PROCEDUREA, and MAIN. PROCEDURED cannot accessthe variables of PROCEDUREB. 109
  • 110. âš« Procedure A can access variables in MAIN since MAIN is at level 1. Therefore the base for the dynamic storage for MAIN is at [EBP-2]. âš« All dynamic variables for MAIN are at a fixed offset from this value. 110
  • 111. âš« B can access variables in A and MAIN by fetching from the display the base addresses of the respective dynamic storage areas. 111
  • 112. LEAVE 112 âš« LEAVE (Leave Procedure) reverses the action of the previous ENTER instruction. The LEAVE instruction does not include any operands. âš« LEAVE copies EBP to ESP to release all stack space allocated to the procedure by the most recent ENTERinstruction. âš« Then LEAVE pops the old value of EBPfrom the stack.
  • 113. FLAG CONTROL INSTRUCTIONS Carry and Direction flag control Instructions 113 Flag Control Instruction Effect STC (Set Carry Flag) CF <- 1 CLC (Clear Carry Flag) CF <- O CMC (Complement Carry Flag) CF <- NOT (CF) CLD (Clear Direction Flag) DF <- O STD (Set Direction Flag) DF <- 1
  • 114. FLAG CONTROL INSTRUCTIONS FlagTransfer Instructions âš« The flag transfer instructions allow a program to alter the other flag other than CF and DF bits with the bit manipulation instructions after transferring these flags to the stack or theAH register. âš« LAHF (Load AH from Flags) copies SF,ZF,AF,PF,and CF to AH bits 7,6,4,2,and 0,respectively (see Figure 3- 22).The contents of the remaining bits (5, 3, and1) are undefined.The flags remain unaffected. âš« SAHF (StoreAH into Flags) transfers bits 7,6,4,2,and 0 fromAH into S F ,ZF ,AF ,PF ,and CF ,respectively 114
  • 115. âš« PUSHF (Push Flags) decrements ESP by two and then transfers the low-order word of the flags register to the word at the top of stack pointed to by ESP. The variant PUSHFD decrements ESP by four, then transfers both words of the extended flags register to the top of the stack pointed to by ESP (the VM and RF flags are not moved,however). âš« POPF (Pop Flags) transfers specific bits from the word at the top of stack into the low-order byte of the flag register,then increments ESPby two.The variant POPFD transfers specific bits from the doubleword at the top of the stack into the extended flags register (the RFandVM flags are not changed,however), then increments ESPby four. 115
  • 116. COPROCESSOR INTERFACE INSTRUCTIONS 116 âš« The 80386 also has features to support emulation of the numeric coprocessor when the coprocessor is absent. âš« ESC (Escape) : Used by Coprocessor is a 5-bit sequence that begins the opcodes that identify floating point numeric instructions. âš« ESC pattern tells 80386 to send the opcode and addresses of operands to numeric coprocessor. âš« The numeric coprocessor uses the escape instructions to perform high-performance, high-precision floating point arithmetic.
  • 117. COPROCESSOR INTERFACE INSTRUCTIONS 117 âš« WAIT (Wait) âš« Suspends (80386) program execution until the 80386 CPU detects that the BUSY pin is inactive. âš« This condition indicates that the coprocessor has completed its processing and CPU may obtain result.
  • 118. SEGMENT REGISTER INSTRUCTIONS (In Groups) Segment-register transfer instructions. MoV ••• ,SegReg MoV SegReg,••• PUSH S egReg POP SegReg Control transfers to another executable segment.: JMPfar CALL far RET far Data pointer instructions. LOS LES LFS LGS 118
  • 119. Data Pointer Instructions 119 âš«LDS (Load Pointer UsingDS) LDS ESI,STRING_X The source operand must be a memory operand, and the destination operand must be a general register. DS receives the segment-selector of the pointer. The destination register receives the offset part of the pointer, which points to a specific location within the segment. âš«LES(Load Pointer UsingES) LESEDI,DESTINATION_X operates identically to LDS except that ESreceives the segment selector rather than DS.
  • 120. âš«LFS (Load Pointer Using FS) Operates identically to LDS except that FSreceives the segment selector rather than DS. âš«LGS (Load Pointer Using GS) Operates identically to LDS except that GS receives the segment selector rather than DS. âš«LSS (Load Pointer Using SS) Operates identically to LDS except that SSreceives the segment selector rather than DS. 120
  • 121. Miscellaneous Instructions 121 âš« LEA (Load EffectiveAddress) Transfers the offset of the source operand (rather than its value) to the destination operand. The source operand must be a memory operand, and the destination operand must be a general register. This instruction is especially useful for initializing registers before the execution of the string primitives (ESI,EDI) LEA EBX,EBCDIC_TABLE âš« NOP (No Operation) NOP (No Operation) occupies abyte of storage but affects nothing but the instruction pointer,EIP. âš« XLAT (Translate) XLAT (Translate) replaced a byte in the AL register with a byte from a user-coded translation table. When XLAT is executed, AL should have the unsigned index to the table addressed by EBX. XLAT changes the contents ofAL from table index to table entry.EBX is unchanged.
  • 122. Feedback 122 âš«Teaching Method âš«Am I audible? âš«Am I interactive with you? âš«Study Material (PPT,Notes etc.) âš«Any Suggestionsare welcome…
  • 123. Solve 123 âš«Explain 80386Architecture âš«Write aprocedure for „ASCII to HEX ‟ and„HEX toASCII ‟Conversion. âš«List and Explain General Purpose Registers. âš«Explain following flags from EFLAG register 1.VM 2.IOPL 3.RF âš«Explain following instructions 1.XOR 2.PUSHA 3.CALL 4.JMP