0% found this document useful (0 votes)
12 views18 pages

MP U1_merged

The document provides a detailed explanation of various instructions and addressing modes in the 80386 microprocessor, including data movement instructions like MOV, PUSH, and POP, as well as addressing modes such as immediate, register, and direct addressing. It also covers decimal arithmetic instructions and the architecture of the 80386 microprocessor, detailing its main units like the Bus Interface Unit and Execution Unit. Examples are provided for each instruction and addressing mode to illustrate their usage.

Uploaded by

create2earn365
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views18 pages

MP U1_merged

The document provides a detailed explanation of various instructions and addressing modes in the 80386 microprocessor, including data movement instructions like MOV, PUSH, and POP, as well as addressing modes such as immediate, register, and direct addressing. It also covers decimal arithmetic instructions and the architecture of the 80386 microprocessor, detailing its main units like the Bus Interface Unit and Execution Unit. Examples are provided for each instruction and addressing mode to illustrate their usage.

Uploaded by

create2earn365
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

1

MICROPROCESSOR UNIT 1:
Q.1) Explain following instructions in microprocessor 80386:
i) MOV ii) PUSH iii) POP iv) CBW v) MOVSX
Ans:
1. MOV (Move Instruction)
• Purpose: Transfers data from one location to another.
• Syntax: MOV destination, source
• Operands:
o Destination: Register, memory location
o Source: Register, memory location, immediate value
Example:
MOV AX, BX ; Moves the content of BX into AX
MOV AL, 05H ; Moves immediate value 05H into AL
MOV [SI], DX ; Moves the content of DX into the memory location pointed by SI

2. PUSH (Push onto Stack)


• Purpose: Pushes a register or memory value onto the stack.
• Syntax: PUSH source
• Operands:
o Source: Register, memory location, segment register
• Example:
PUSH AX ; Pushes the content of AX onto the stack
PUSH BX ; Pushes the content of BX onto the stack
PUSH [BP] ; Pushes the value at the memory location BP onto the stack
Operation:

December 1, 2024 1
2

• Decreases ESP (Stack Pointer) by 2 (or 4 in 32-bit mode).


• Stores the value at the new stack address.

3. POP (Pop from Stack)


• Purpose: Pops a value from the stack into a register or memory location.
• Syntax: POP destination
• Operands:
o Destination: Register, memory location
• Example:
POP AX ; Pops the top value from the stack into AX
POP BX ; Pops the next value from the stack into BX
Operation:
• Loads the value from the stack into the destination.
• Increases ESP (Stack Pointer) by 2 (or 4 in 32-bit mode).

4. CBW (Convert Byte to Word)


• Purpose: Converts a signed byte in AL to a signed word in AX.
• Syntax: CBW
• Operation:
o AL → AX (Sign-extends AL into AH)
• Example:
MOV AL, -5 ; AL = 0xFB (signed -5)
CBW ; AH = 0xFF, AX = 0xFFFB (-5 in 16-bit)

5. MOVSX (Move with Sign Extension)

December 1, 2024 2
3

• Purpose: Moves a smaller signed value (byte/word) into a larger register


(word/dword) and sign-extends it.
• Syntax: MOVSX destination, source
• Operands:
o Destination: 16-bit or 32-bit register
o Source: 8-bit or 16-bit register/memory
Example :
MOV AL, -5 ; AL = 0xFB (-5)
MOVSX AX, AL ; AX = 0xFFFB (-5 in 16-bit)
MOVSX EAX, AX ; EAX = 0xFFFF_FFFB (-5 in 32-bit)

Q.2) Explain following addressing modes in 80386 processor with example

i) Immediate addressing mode ii) Register addressing mode iii) Register Indirect
addressing mode.
Ans:
Addressing Modes in 80386 Processor with Examples
The 80386 microprocessor supports various addressing modes to access data from
memory and registers efficiently. Below are three important addressing modes with
explanations and examples.

1. Immediate Addressing Mode


• Definition:
In this mode, the operand is a constant value (immediate data) that is directly
specified in the instruction.
• Example:
MOV AX, 1000H ; Moves immediate value 1000H into AX
ADD BX, 05H ; Adds immediate value 05H to BX

December 1, 2024 3
4

• Usage:
Used when a fixed value needs to be loaded into a register or memory.

2. Register Addressing Mode


• Definition:
In this mode, the operand is located in a register, and the instruction
directly refers to that register.
• Example:
MOV AX, BX ; Moves the content of BX into AX
ADD DX, CX ; Adds the content of CX to DX
Usage:
Provides fast execution since data is accessed directly from the registers.
3. Register Indirect Addressing Mode
• Definition:
The memory address of the operand is stored in a register, and the
instruction accesses the data indirectly through that register.
• Example:
MOV AX, [BX] ; Moves the value from the memory location pointed by BX into AX
MOV [SI], CX ; Moves the value of CX into the memory location pointed by SI
• Usage:
Useful for accessing arrays, pointers, and dynamic memory locations
efficiently.

Q.3) With necessary example, explain various Decimal Arithmetic Instructions.


Ans:

December 1, 2024 4
5

Decimal Arithmetic Instructions in 80386 Processor


The 80386 processor provides special instructions for performing arithmetic
operations on Binary-Coded Decimal (BCD) numbers. These instructions ensure
correct decimal adjustments after arithmetic operations.
Types of Decimal Arithmetic Instructions
1. DAA (Decimal Adjust after Addition)
2. DAS (Decimal Adjust after Subtraction)
3. AAA (ASCII Adjust after Addition)
4. AAS (ASCII Adjust after Subtraction)
5. AAM (ASCII Adjust after Multiplication)
6. AAD (ASCII Adjust before Division)

1. DAA (Decimal Adjust after Addition)


• Purpose: Adjusts the result of an addition operation to get a valid BCD
result.
• Usage: After adding two BCD numbers.
• Example:
MOV AL, 27H ; Load AL with a BCD value (27 in decimal)
ADD AL, 25H ; Add another BCD value (25 in decimal)
DAA ; Adjust AL for valid BCD result

2. DAS (Decimal Adjust after Subtraction)


• Purpose: Adjusts the result of a subtraction operation to get a valid BCD
result.
• Usage: After subtracting two BCD numbers.
• Example:

December 1, 2024 5
6

MOV AL, 25H ; Load AL with a BCD value (25 in decimal)


SUB AL, 12H ; Subtract another BCD value (12 in decimal)
DAS ; Adjust AL for valid BCD result

3. AAA (ASCII Adjust after Addition)


• Purpose: Adjusts the result of an addition operation performed on
unpacked ASCII numbers.
• Usage: After adding two ASCII values (0-9 range).
• Example:
MOV AL, '5' ; ASCII code of '5' (35H)
ADD AL, '3' ; ASCII code of '3' (33H)
AAA ; Adjust AL for valid ASCII result

4. AAS (ASCII Adjust after Subtraction)


• Purpose: Adjusts the result of a subtraction operation on unpacked ASCII
numbers.
• Usage: After subtracting ASCII values (0-9 range).
• Example:
MOV AL, '8' ; ASCII code of '8' (38H)
SUB AL, '3' ; ASCII code of '3' (33H)
AAS ; Adjust AL for valid ASCII result

6. AAD (ASCII Adjust before Division)


• Purpose: Adjusts BCD numbers before division to prepare them for division
operation.

December 1, 2024 6
7

• Usage: Before dividing BCD numbers.


• Example:
MOV AX, 0201H ; Load AX with a BCD number (201 in decimal)
AAD ; Convert to unpacked BCD form
DIV BL ; Divide by BL

Q.4) Explain following addressing modes in 80386 processor with example


i) Direct addressing mode
ii) Index addressing mode
iii) Based-scaled-index with displacement addressing mode
Ans:
Addressing Modes in 80386 Processor with Examples
The 80386 microprocessor supports multiple addressing modes for efficient data
access. Below are the explanations and examples of Direct Addressing Mode,
Index Addressing Mode, and Base-Scaled-Index with Displacement Addressing
Mode.

1. Direct Addressing Mode


• Definition:
The operand is stored in a memory location, and the instruction directly
specifies the memory address.
• Syntax:
MOV AL, [1234H] ; Move data from memory location 1234H into AL
Example:
MOV AX, [2000H] ; Load AX with the value at memory address 2000H

December 1, 2024 7
8

• Usage:
o Used when accessing fixed memory locations.
o Useful for accessing global variables or constants.

2. Index Addressing Mode


• Definition:
A memory location is accessed using an index register (SI or DI) combined
with a base address.
• Syntax:
MOV AX, [SI] ; Access memory at the address stored in SI
MOV [DI], BX ; Store BX at the memory location pointed by DI
Example:
MOV SI, 2000H ; Load base address in SI
MOV AX, [SI] ; Move value from memory at SI into AX
• Usage:
o Used for arrays and tables.
o Useful for sequential memory access, such as iterating through an
array.

3. Base-Scaled-Index with Displacement Addressing Mode


• Definition:
o This mode uses a base register (BX or BP), an index register (SI or DI),
a scale factor, and an optional displacement to calculate the
memory address.
o Useful for accessing elements in arrays.
• Syntax:

December 1, 2024 8
9

MOV AX, [EBX + ESI * 4 + 20H] ; Access memory at EBX + (ESI * 4) + 20H
Example:
MOV EBX, 1000H ; Base address
MOV ESI, 2 ; Index
MOV AX, [EBX + ESI * 4 + 10H] ; Access element at computed address
• Usage:
o Used for 2D arrays, complex data structures, and efficient indexing.
o Helps in dynamic memory access in programs.

Summary

Addressing Mode Formula Example

Direct Addressing Mode [Address] MOV AL, [1234H]

Index Addressing Mode [Base Register + Index] MOV AX, [SI]

Base-Scaled-Index with [Base + Index * Scale + MOV AX, [EBX + ESI *


Displacement Displacement] 4 + 20H]

These modes help in efficient memory access and complex data manipulations in
the 80386

December 1, 2024 9
1

1.Explain the architecture of the 80386 microprocessor with an appropriate


diagram

Architecture of the 80386 Microprocessor

The architecture of the 80386 can be divided into the following main units:

1. Bus Interface Unit (BIU)


o Manages communication between the CPU and memory or I/O devices.
o Handles address generation, data transfer, and instruction fetching.
o Uses a 32-bit data bus and a 32-bit address bus.
2. Code Prefetch Unit (CPU)
o Fetches instructions from memory to improve execution speed.
o Uses a 16-byte prefetch queue to store upcoming instructions.
3. Instruction Decode Unit (IDU)
o Decodes the prefetched instructions.
o Converts them into micro-instructions for execution.
4. Execution Unit (EU)
o Performs arithmetic and logic operations.
o Contains 32-bit general-purpose registers and a 32-bit ALU (Arithmetic
Logic Unit).
5. Memory Management Unit (MMU)
o Supports segmentation and paging for efficient memory management.
o Can address up to 4 GB of physical memory and 64 TB of virtual
memory.
6. Segmentation Unit
o Divides memory into segments (Code, Data, Stack, and Extra).
o Each segment can be up to 4 GB in size.
7. Paging Unit
o Implements virtual memory by dividing memory into 4 KB pages.
o Supports a two-level page table hierarchy.
8. Control Unit (CU)
o Controls the overall operation of the processor.
o Manages instruction sequencing and execution.
2
3

2.Describe the following addressing modes of 80386 with example

i) Index addressing mode ii) Direct addressing mode iii) Based index mode

Addressing Modes of the 80386 Microprocessor

The 80386 supports various addressing modes to access memory efficiently. Below are
the descriptions and examples of the requested addressing modes:

(i) Index Addressing Mode

 In this mode, an index register (SI or DI) is used to determine the memory
location.
 The effective address is calculated as:
Effective Address=Base Address+Index Register\text{Effective Address} =
\text{Base Address} + \text{Index
Register}Effective Address=Base Address+Index Register
 Used for accessing arrays or tables.

Example:
MOV EAX, [ARRAY + ESI]

 Here, ARRAY is the base address, and ESI acts as the index.
 The processor adds ESI to ARRAY to get the actual memory address.

(ii) Direct Addressing Mode

 The operand's memory address is directly specified in the instruction.


 No calculations are needed to determine the address.

Example:
MOV AL, [1000H]

 The instruction directly accesses the memory location 1000H.


 Useful for accessing fixed memory locations.
4

(iii) Based Index Addressing Mode

 Uses both a base register (BX, BP) and an index register (SI, DI) to determine the
memory location.
 The effective address is calculated as:
Effective Address=Base Register+Index Register\text{Effective Address} =
\text{Base Register} + \text{Index
Register}Effective Address=Base Register+Index Register
 Used for accessing complex data structures like arrays of records.

Example:
MOV EAX, [EBX + ESI]

 Here, EBX acts as the base register, and ESI is the index register.
 The memory location accessed is the sum of EBX and ESI.

3. Describe the use of various 80386 Data Movement Instructions in assembly

language programming with examples.

1. General Data Transfer Instructions

These instructions transfer data between registers, memory, and immediate values.

Instruction Description Example

Moves data between registers or MOV EAX, EBX (Move EBX value
MOV
memory to EAX)

Exchanges values between two XCHG EAX, ECX (Swap EAX and
XCHG
operands ECX)

PUSH Pushes data onto the stack PUSH EAX (Store EAX on stack)

POP EBX (Load value from stack


POP Pops data from the stack
into EBX)

Example: MOV Instruction


MOV EAX, 1234H ; Load immediate value 1234H into EAX
MOV EBX, EAX ; Copy value from EAX to EBX
MOV [VAR], EBX ; Store EBX value in memory location VAR
5

2. Stack Data Transfer Instructions

These instructions handle pushing and popping data from the stack.

Instruction Description Example

PUSH Pushes data onto the stack PUSH ECX (Save ECX on stack)

Removes data from the POP EDX (Retrieve last pushed value into
POP
stack EDX)

Example: PUSH and POP


PUSH EAX ; Save EAX on the stack
MOV EAX,5678H ; Change EAX value
POP EAX ; Restore original EAX value

3. I/O Data Transfer Instructions

These instructions transfer data between CPU and I/O ports.

Instruction Description Example

IN Reads data from an I/O port IN AL, 60H (Read from port 60H into AL)

OUT Writes data to an I/O port OUT 70H, AL (Send AL to port 70H)

Example: IN and OUT Instructions


MOV DX, 03F8H ; COM1 serial port
IN AL, DX ; Read byte from the port
OUT DX, AL ; Write byte back to the port

4. Describe the various operating modes of 80386


6

1. Real Mode

Description:

 Backwards-compatible mode with the 8086/8088 processors.


 Only 1 MB of memory is accessible (20-bit addressing: 2^20 = 1 MB).
 No memory protection or multitasking support.
 Direct hardware access, making it useful for booting and running older software
(like MS-DOS).

Key Features:

✅ 16-bit registers and instructions.


✅ Segmented memory model (each segment max 64 KB).
✅ Can switch to Protected Mode, but requires a system reset to return.

2. Protected Mode

Description:

 Fully 32-bit mode, enabling advanced memory management.


 Supports multitasking, virtual memory, and memory protection.
 Can access up to 4 GB of physical memory (32-bit addressing: 2^32 = 4 GB).
 Uses segmentation and paging for efficient memory management.

Key Features:

✅ Memory Protection: Prevents programs from accessing each other’s memory.


✅ Multitasking: Allows multiple programs to run simultaneously.
✅ Virtual Memory: Can use hard disk space as RAM.
✅ Segmentation & Paging: Used for memory management and security.

Example Use Case:

Switching to Protected Mode (Assembly Code Example)


MOV EAX, CR0 ; Load Control Register 0
OR EAX, 1 ; Set the PE (Protection Enable) bit
MOV CR0, EAX ; Enable Protected Mode
JMP CODE_SEG:START ; Far jump to the protected mode code
7

3. Virtual 8086 Mode (VM86 Mode)

Description:

 Allows running 8086 programs inside a Protected Mode environment.


 Provides DOS compatibility while using Protected Mode features.
 Each VM86 task has its own 1 MB memory space, simulating real mode
execution.

Key Features:

✅ Runs multiple DOS applications simultaneously.


✅ Uses Protected Mode memory protection for safety.

5. Explain the General Registers and Segment Registers of 80386 with an


appropriate diagram.
1. General-Purpose Registers (GPRs)

These 32-bit registers are used for data storage, arithmetic operations, and
addressing. They can also be accessed as 16-bit and 8-bit registers for backward
compatibility.

List of General-Purpose Registers


8

Register Purpose Usage

Stores results of arithmetic and logic MOV EAX,


EAX (Accumulator Register)
operations 1000H

Used for memory addressing and MOV EBX,


EBX (Base Register)
general storage ARRAY

ECX (Counter Register) Loop counter in iteration instructions LOOP label

Used in multiplication and I/O


EDX (Data Register) MUL EDX
operations

Used for string operations (source


ESI (Source Index Register) MOVSB
pointer)

EDI (Destination Index Used for string operations (destination


STOSB
Register) pointer)

MOV EBP,
EBP (Base Pointer Register) Points to stack frame in function calls
ESP

ESP (Stack Pointer


Points to the top of the stack PUSH EAX
Register)

Breakdown of 32-bit, 16-bit, and 8-bit Access

Each register can be accessed in different sizes:

 32-bit (Full register): EAX, EBX, ECX, EDX


 16-bit (Lower half): AX, BX, CX, DX
 8-bit (Lower and upper halves of 16-bit registers):
o Lower: AL, BL, CL, DL
o Upper: AH, BH, CH, DH

2. Segment Registers

The 80386 uses segmentation for memory management. Segment registers store the base
address of memory segments.

List of Segment Registers


9

Segment Register Purpose Usage

CS (Code Segment) Points to the segment containing the program code MOV CS, AX

DS (Data Segment) Points to the segment containing data MOV DS, AX

SS (Stack Segment) Points to the segment where stack operations occur MOV SS, AX

ES (Extra Segment) Additional segment used for data MOV ES, AX

FS & GS Extra segment registers for specialized use MOV FS, AX

Diagram of 80386 Registers

You might also like