Microprocessors-based systems (under graduate course) Lecture 3 of 9

18
Microprocessor-Based Systems Dr. Randa Elanwar Lecture 3

Transcript of Microprocessors-based systems (under graduate course) Lecture 3 of 9

Microprocessor-Based Systems

Dr. Randa Elanwar

Lecture 3

Lecture Content

• 8086/8088 microprocessor registers• 8086/8088 microprocessor instruction set

2Microprocessor-Based Systems Dr. Randa Elanwar

8086 Register organization• 8086 has a powerful set of registers containing general purpose

and special purpose registers. • All the registers of 8086 are 16-bit registers. The general purpose

registers, can be used as either 8-bit registers or 16-bit registers. • The general purpose registers are either used for holding data,

variables and intermediate results temporarily or for other purposes like a counter.

• The special purpose registers are used as segment registers, pointers, index registers or as offset storage registers for particular addressing modes.

• The register set is categorized into four groups: (a) general data registers, (b) segment registers, (c) pointers and index registers, (d) flag register.

3Microprocessor-Based Systems Dr. Randa Elanwar

8086 Register organization

• The registers AX, BX, CX and DX are the general purpose 16-bit registers. AX is used as 16-bit accumulator, with the lower 8-bits of AX designated as AL and higher 8-bits as AH. AL can be used as an 8-bit accumulator for 8-bit operations.

• Usually the letters L and H specify the lower and higher bytes of a particular register.

4Microprocessor-Based Systems Dr. Randa Elanwar

8086 Register organization

5Microprocessor-Based Systems Dr. Randa Elanwar

•There are four segment registers, Code Segment Register (CS), Data Segment Register (DS), Extra Segment Register (ES) and Stack Segment Register (SS).•Thus the CS, DS, SS and ES segment registers respectively contain the addresses for the code, data, stack and extra top locations in memory segments.•The pointers IP, BP and SP usually contain offsets within the code, data and stack memory segments respectively.

8086/8088 instruction set• The 8086/8088 instructions are categorized into the following

main types: 1. Data Copy/Transfer Instructions: This type of instructions are

used to transfer data from source operand to destination operand.

All the store, move, load, exchange, input and output instructions belong to this category.

2. Arithmetic and Logical Instructions: these instructions are used to perform arithmetic, logical, increment, decrement, compare and scan.

3. Branch Instructions: These instructions transfer control of execution to the specified address.

All the call, jump, interrupt and return instructions belong to this class.6Microprocessor-Based Systems Dr. Randa Elanwar

8086/8088 instruction set4. Loop Instructions: These are useful to implement different loop

structures.5. Machine Control Instructions: These instructions control the

machine status. NOP, HLT, WAIT and LOCK instructions belong to this class.

6. Flag Manipulation Instructions: All the instructions which directly affect the flag register, come under this group of instructions.

Instructions like CLD,STD,CLI,STI, etc. belong to this category of instructions.

7. Shift and Rotate Instructions: These instructions involve the bitwise shifting or rotation in either direction with or without a count in CX.

8. String Instructions: These instructions involve various string manipulation operations like load, move, scan, compare, store, etc.

These instructions are only to be operated upon the strings

7Microprocessor-Based Systems Dr. Randa Elanwar

8086/8088 instruction set (MOV)Data Copy/Transfer Instructions:• MOV: Move This data transfer instruction transfers data from one

register/memory location to another register/memory location. • Again: there are different types of registers: general or special

purpose registers which are located in the execution unit of CPU (e.g., AX, CX, SP, etc.), segment registers holding parts of memory location addresses which are located in the BIU unit of the CPU (e.g., DS, SS, CS, etc.)

• For the MOV instruction, the source may be any one of the segment registers or other general or special purpose registers or a memory location and, another register or memory location may act as destination.

8Microprocessor-Based Systems Dr. Randa Elanwar

8086/8088 instruction set (MOV)Data Copy/Transfer Instructions:• However, in case of immediate addressing mode (i.e., instruction

includes the value to be stored), a segment register cannot be a destination register.

• In other words, direct loading of the segment registers with immediate data is not permitted. To load the segment registers with immediate data, one will have to load any general-purpose register with the data and then it will have to be moved to that particular segment register.

• Example: Load DS with 5000H.1. MOV DS, 5000H; Not permitted (invalid)• Thus to transfer an immediate data into the segment register, the

correct procedure is given below.2. MOV AX, 5000H• MOV DS, AX

9Microprocessor-Based Systems Dr. Randa Elanwar

8086 addressing modes• The addressing modes describe the types of operands and the way they

are accessed for executing an instruction:• 1. Immediate: In this type of addressing, immediate data is a part of

instruction, and appears in the form of successive byte or bytes.Example 1: MOV AX, 0005H

• In the above example, 0005H is the immediate data. The immediate data may be 8-bit or 16-bit in size.

• 2. Direct: In the direct addressing mode, a 16-bit memory address (offset) is directly specified in the instruction as a part of it.

Example 2: MOV AX, [5000H]• Here, data resides in a memory location in the data segment, whose

effective address may be computed using 5000H as the offset address and content of DS as segment address. The effective address, here, is 10H*DS+5000H.

10Microprocessor-Based Systems Dr. Randa Elanwar

8086 addressing modes• 3. Register: In register addressing mode, the data is stored in a register

and it is referred using the particular register. All the registers, except IP, may be used in this mode.

Example 3: MOV BX, AX.• 4. Register Indirect: Sometimes, the address of the memory location

which contains data or operand is determined in an indirect way, using the offset registers. This mode of addressing is known as register indirect mode. In this addressing mode, the offset address of data is in either BX or SI or Dl register.

• The default segment is either DS or ES. The data is supposed to be available at the address pointed to by the content of any of the above registers in the default data segment.

Example 4: MOV AX, [BX]• Here, data is present in a memory location in DS whose offset address is in

BX. The effective address of the data is given as 10H*DS+[BX].11Microprocessor-Based Systems Dr. Randa Elanwar

8086/8088 instruction set (MOV)Data Copy/Transfer Instructions:• Note that both the source and destination operands cannot be memory locations.

• Memory locations are distinguished from registers using the square brackets [ ].

• MOV instruction addressing modes:• MOV AX, 5000H; Immediate• MOV AX, BX; Register• MOV AX, [SI]; Indirect• MOV AX, [2000 H]; Direct

12Microprocessor-Based Systems Dr. Randa Elanwar

8086/8088 instruction set (XCHG)Data Copy/Transfer Instructions:• XCHG: Exchange This instruction exchanges the contents of

the specified source and destination operands, which may be registers or one of them may be a memory location.

• However, exchange of data contents of two memory locations is not permitted.

• Example:• XCHG [5000H], AX ; This instruction exchanges data

between AX and a memory location with offset [5000H] in the data segment.

• XCHG BX ; This instruction exchanges data between AX and BX.

13Microprocessor-Based Systems Dr. Randa Elanwar

8086/8088 instruction set (ADD-ADC)Arithmetic and Logical Instructions:• ADD: Add This instruction adds an immediate data or contents of a

memory location specified in the instruction or a register (source) to the contents of another register (destination) or memory location. The result is in the destination operand.

• However, both the source and destination operands cannot be memory operands. That means memory to memory addition is not possible.

• Also the contents of the segment registers cannot be added using this instruction

• ADC: Add with Carry This instruction performs the same operation as ADD instruction, but adds the carryflag bit (which may be set as a result of the previous calculations) to the result.

14Microprocessor-Based Systems Dr. Randa Elanwar

8086/8088 instruction set (ADD-ADC)• Example• ADD AX, 0100H Immediate• ADC AX, 0100H Immediate• ADD AX, BX Register• ADC AX, BX Register• ADD AX, [SI] Register indirect• ADC AX, [SI] Register indirect• ADD AX, [5000H] Direct• ADC AX, [5000H] Direct• ADD [5000H] 0100H Immediate• ADC [5000H] 0100H Immediate• ADD 0100H Destination AX (implicit)• ADC 0100H Destination AX (implicit)

15Microprocessor-Based Systems Dr. Randa Elanwar

8086/8088 instruction set (INC-DEC)Arithmetic and Logical Instructions:• INC: Increment This instruction increments the contents of the specified

register or memory location by 1. Immediate data cannot be operand of this instruction.

• Example• INC AX Register• INC [BX] Register indirect• INC [5000H] Direct

• DEC: Decrement The decrement instruction subtracts 1 from the contents of the specified register or memory location. Immediate data cannot be operand of the instruction.

• Example• DEC AX Register• DEC [5000H] Direct

16Microprocessor-Based Systems Dr. Randa Elanwar

8086/8088 instruction set (SUB-SBB)Arithmetic and Logical Instructions:• SUB: Subtract instruction subtracts the source operand from the

destination operand and the result is left in the destination operand. • Source operand may be a register, memory location or immediate

data and the destination operand may be a register or a memory location, but source and destination operands both must not be memory operands.

• Destination operand can not be an immediate data.

• SBB: The subtract with borrow instruction subtracts the source operand and the borrow flag (CF) which may reflect the result of the previous calculations, from the destination operand.

• Subtraction with borrow, here means subtracting 1 from the subtraction obtained by SUB, if carry (borrow) flag is set.

17Microprocessor-Based Systems Dr. Randa Elanwar

8086/8088 instruction set (SUB-SBB)• Example• SUB 0100H Immediate [destination AX]• SBB 0100H Immediate [destination AX]• SUB AX, BX Register• SBB AX, BX Register• SUB AX, [5000H] Direct• SBB AX, [5000H] Direct• SUB [5000H], 0100 Immediate• SBB [5000H], 0100 Immediate

18Microprocessor-Based Systems Dr. Randa Elanwar