8086 Instruction Set PDF
Document Details
Uploaded by Deleted User
Dalaman Mamarai College of Engineering
Ms. Pallavi Bute
Tags
Summary
This document provides an overview of the 8086 instruction set, covering addressing modes, instruction format, and programming examples. It's designed as a study guide or course material. The document details the different types of addressing modes available in the 8086 architecture.
Full Transcript
Unit 2 8086 Instruction Set Ms.Pallavi Bute Content 8086 Instruction Set Addressing Modes Instruction Format 8086 Programming Integer Instruction & Computation Data Transfer Instruction Arithmetic Instruction & their use in programming Addressing...
Unit 2 8086 Instruction Set Ms.Pallavi Bute Content 8086 Instruction Set Addressing Modes Instruction Format 8086 Programming Integer Instruction & Computation Data Transfer Instruction Arithmetic Instruction & their use in programming Addressing Modes in 8086 Lecture Outcome After completion of this lecture student able analyze different addressing modes & form effective address of addressing modes. Addressing Modes in 8086 Addressing mode tells us what is the type of the operand and the way they are accessed from the memory for execution of an instruction and how to fetch particular instruction from the memory. There are mainly 8 addressing modes of an 8086 microprocessor. According to flow of instruction execution, the instructions may be categories as Sequential Control Flow Instruction Control Transfer Instruction Opcode& Operand in Microprocessor 8086 Opcode is shortcut of Operation Code An Opcode is a single instruction executed by CPU. In machine language it is a binary or hexadecimal value. In assembly language mnemonic form an Opcode is a command such as MOV,ADD etc EXAMPLE MOV AX,1000H; MOV is Opcode ; AX(Destination) is an operand ; 1000H(Source) Operand can be manipulated by Opcode. Addressing Modes in 8086 1. Immediate Addressing Modes In this type of addressing, immediate data is part of instruction & appears in the form of successive byte or bytes Source operand is Constant Example: MOV Ax, 0005H Transfer the source, immediate byte or word of data, into the destination register or memory location. Immediate addressing modes can be used to load information into any register except segment & flag register. Addressing Modes in 8086 Examples of Immediate Addressing Modes MOV AX,2500H MOV BL,22H MOV CX,625H Data must be move to general purpose register then it will move to segment register MOV AX,2500H MOV DS,AX MOV DS,2500H ILLEGAL Instruction Addressing Modes of 8086 2.Direct Addressing Modes Moves a byte or word between memory location & register The data is in some memory location & address of the data in memory comes immediately after the instruction In this a 16 bit memory address(offset) is directly specified in the instruction as a part of it Example: MOV CX,[4321H] Addressing Modes of 8086 Example of Direct Addressing Modes MOV CX, [4321H] This instruction moves data from location 4321H in the data segment into CX. The physical/effective address is calculated as DS * 10H + 4321[offset] Assume DS = 5000H ∴PA = 50000 + 4321 = 54321H ∴CX ← [54321H] Addressing Modes in 8086 3.Register Addressing Modes In this mode, operands are specified using registers. This addressing mode is normally preferred because the instructions are compact and fastest executing of all instruction forms. Registers may be used as source operands, destination operands or both. All the register except IP can be used in this mode Example: MOV AX, BX This instruction copies the contents of BX register into AX register. AX ← BX Addressing Modes in 8086 4.Register Indirect Addressing Mode Transfers a byte or word between a register and a memory location addressed by an index or base register. In this offset address of data is in either BX, SI, DI. 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. MOV AX, [DI] ADD AL, [BX] MOV AX, [SI] Physical Address MOV AX, [BX] ; moves into AX the contents of the memory location pointed to by DS:BX,, 1000:1234 The physical address is calculated as1000x10+1234=11234H Addressing Modes in 8086 5.Index Addressing Mode In this addressing mode, offset of the operand is stored in one of the index registers.DS is default segment of index registers SI & DI Example MOV AX,[SI] Effective address =10 H * DS+[SI] Addressing Modes of 8086 6.Register Relative Addressing Modes In this, data is available at an effective address formed by adding an 8 bit or 16-bit displacement with content, any one of the registers BX, BP, SI, DI in the default (DS or ES) segment. Example MOV AX,50H+[BX] Effective Address 10H * DS + 50H +[BX] Addressing Modes of 8086 7.Based Index Addressing Mode The effective address of data is formed by adding content of base register BX or BP to the content of index register. The default segment register may be ES or DS Example MOV AX,[BX][SI] Effective Address 10H * DS +[BX]+[SI] Addressing Mode of 8086 8.Relative Based Indexed Addressing Mode Here the effective address is formed by adding an 8 bit or 16-bit displacement with the sum of the content of any one of the base registers(BX OR BP)& any one of the index registers in the default segment. Example MOV AX,50H[BX][SI] Effective Address 10H * [BX]+[SI] +50H Identify the Addressing Modes 1. MOV AL,BL 2. MOV AX,OFFFH 3. MOV [DI],AX 4. MOV DI,[SI] 5. MOV [BX]+0400H,CX 6. MOV [DI]+0400H,AX 7. MOV [BX][DI]+0400H,AX The content of different register are given below.Form effective addresses for different addressing modes. Offset(Displacement)=5000H [AX]-1000H, [BX]-2000H, [SI]- 3000H, [DI]-4000H, [BP]-5000H, [SP]-6000H, [CS]-0000H, [DS]-1000H, [SS]-2000H, [IP]-7000H 1. Direct addressing mode 2. Register Indirect mode 3. Register Relative mode 4. Based Index mode Instruction Format Instruction Format A machine language instruction format has one or more number of fields associated with it. The first field is called as operation code field or op-code field, which indicates the type of operation to be performed by the CPU. The instruction format also contains other fields known as operand fields. The CPU executes the instruction using the information which reside in these fields. There are six general formats of instructions in 8086 instruction set. The length of an instruction may vary from 1 byte to 6 bytes. The instruction formats are described as follows Instruction Format 1. One Byte Instruction This format is only one byte long and may have the implied data or register operands. The least significant 3-bits of the opcode are used for specifying the register operand, if any. Otherwise, all the 8 bits form an opcode and the operands are implied Instruction Format 2. Register to Register This format is 2 bytes long. The first byte of the code specifies the operation code and width of the operand specified by ‘w’ bit. The second byte of the code shows the register operands and R/M field, as shown below. The register represented by the REG field is one of the operands. The R/M field specifies another register or memory location i.e. the other operand. Instruction Format 3. Register to/from Memory with no Displacement This format is also 2 bytes long and similar to the Register to Register format except for the MOD field as shown. The MOD field shows the mode of addressing. The MOD, R/M, REG and the ‘W’ fields are decided in Table 2.2 Instruction Format 3. Register to/from Memory with no Displacement Table 2.2 : Addressing Mode & Corresponding MOD,REG,R/M &W Instruction Format 4. Register to/from Memory with Displacement This type of instruction format contains 1 or 2 additional bytes for displacement along with 2 byte format of the register to/from memory without displacement. The format is as shown below Instruction Format 5. Immediate Operand to Register In this format, the first byte as well as the 3-bits from the second byte which are used for REG field in case of register to register format are used for opcode. It also contains one or two bytes of immediate data. The complete instruction format is as shown below. Instruction Format 6. Immediate Operand to Memory with 16 bit Displacement This type of instruction format requires 5 or 6 bytes for coding. The first 2 bytes contain the information regarding OPCODE, MOD and R/M fields. The remaining 4 bytes contain 2 bytes of displacement and 2 bytes of data as shown. Instruction Set in 8086 Lecture no.12,13 Outcome After completion of this lecture student able analyze data transfer & athematic instruction set. Instruction Set in 8086 The Instruction set of 8086 microprocessor is classified into 7, they are:- ・ Data transfer instructions ・ Arithmetic& logical instructions ・ Program control transfer instructions ・ Machine Control Instructions ・ Shift /Rotate instructions ・ Flag manipulation instructions ・ String instructions Instruction Set in 8086 Data Transfer Instruction It transfer data from one register/memory to another register/memory location MOV Instruction PUSH/POP Instruction (Stack) IN/OUT instruction XCHG Instruction XLAT Instruction LEA Instruction LDS Instruction LES Instruction Instruction Set in 8086 Data Transfer Instruction: MOV Instruction In this data transfers from one register/memory location to another register/memory location. In case of immediate addressing mode, a segment register can not be destination register. Direct loading of the segment register with immediate data is not permitted. Load DS with 5000H MOV AX,5000H MOV DS,AX Instruction Set in 8086 Data Transfer Instruction IN: Input The Port This instruction is used for reading an input port. The address in the input port may be specified in the instruction directly or indirectly. DX is the only register which is allowed to carry the port address. If the port address is 16 bit it must be in DX. Example 1. IN AL,03H This instruction reads data from 8 bit port whose address is 03 H & stores it in AL Instruction Set in 8086 Data Transfer Instruction IN: Input The Port Example IN AX,DX This instruction read data from 16 bit port whose address is in DX & stores it in AX. MOV DX,0800H; The 16 bit address is taken in DX IN AX, DX ;Read the contents of the port in AX Instruction Set in 8086 Data Transfer Instruction OUT: Output to the Port This instruction is used for writing to an output port. The address of the output port may be specified in the instruction directly or implicitly in DX Example OUT 03H,AL ;This sends data variable in AL to a port whose address is 03H OUT DX,AX; This sends data available in AX to a port whose address is specified implicitly in DX MOV DX,0300H;The 16 bit port address is taken in DX OUT DX,AX ;Write the contents of AX to a port of which address is in DX. Instruction Set in 8086 Data Transfer Instruction XCHG Exchange Instruction This instruction exchange the contents of the specified source & destination operands which may be registers or one of them may be a memory location. However exchange of the content of two memory location is not permitted. Example XCHG AX,BX; Exchange data between AX,BX XCHG [5000H],AX; Exchange data between AX & memory location XCHG [5000H],[1000H] ;Not permitted Instruction Set in 8086 Data Transfer Instruction XLAT Instruction This instruction converts the content of AL register into the number stored in a memory table This instruction uses the direct look up technique often used to covert one code to another. Execution of XLAT replaced the content of AL by the content of the accessed look up table location. Instruction Set in 8086 Data Transfer Instruction LEA: Load Effective Address LEA loads the specified register with the offset of a memory location Example LEA BX,ADR; effective address of label ADR i..e offset of ADR will be transferred to register(BX) LEA SI,ADR[BX];OFFSET of label ADR will be added to content of BX to form effective address & it will be loaded in SI Instruction Set in 8086 Data Transfer Instruction LDS/LES :Load Pointer to DS/ES This instruction loads the DS or ES register & the specified destination register in the instruction with the content of the memory location specified as source in the instruction. Instruction Set in 8086 Arithmetic Instruction(Addition) 1. ADD: Add byte or word 2. ADC: Add word or byte with carry 3. INC: Increment byte or word by 1 4. DEC: Decrement byte word by 1 5. AAA: ASCII adjust for addition 6. DAA: Decimal adjust AL after addition Instruction Set in 8086 Arithmetic Instruction(Subtraction) 7. SUB :Subtract byte or word 8. SBB: Subtract with borrow 9. NEG: Negate byte or word 10. AAS: ASCII adjust for subtraction 11. DAS: Decimal adjust for subtraction Instruction Set in 8086 Arithmetic Instruction(Multiplication) 12. MUL : Multiply byte or word unsigned 13. IMUL : Integer multiply byte or word 14. AAM: ASCII adjust for multiply Arithmetic Instruction(Division) 15. DIV: Divide byte or word unsigned 16. IDIV : Integer divide byte or word 17. AAD : ASCII adjust for division 18. CBW: Convert byte or word 19. CWD: Convert word to double word Instruction Set in 8086 Arithmetic Instruction(Addition) 1. ADD: Addition This instruction add an immediate data or contents of a memory location specified in the instruction or register to the contents of the other register or memory location. Example ADD AX,0100H ADD AX,BX ADD AX,[SI] ADD AX, ADD 0100H Destination AX(implicit) Instruction Set in 8086 Arithmetic Instruction(Addition) 2. ADC: Add with carry This instruction performs the same operation as ADD instruction, but adds the carry flag bit (which may be set as a result of the previous calculation)to the result. Example ADC 0100H (AX implicit) ADC AX,BX ADC AX,[SI] ADC AX, Instruction Set in 8086 Arithmetic Instruction(Addition) 3. INC: Increment This instruction increase the content 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 Instruction Set in 8086 Arithmetic Instruction(Addition) 4. DEC: Decrement This instruction decrease the content of the specified register or memory location by 1 (Immediate data cannot be operand of this instruction Example DEC AX Register DEC [BX] Register Indirect DEC [5000H] Direct Instruction Set in 8086 Arithmetic Instruction(Addition) 5. AAA : ASCII Adjust After Addition This instruction is executed after ADD instruction that Add two ASCII operand to a give a byte of the result in AL. The AAA instruction convert the resulting content of AL to unpacked decimal digitals Example Continue…. What is Unpacked BCD Digit ? Unpacked BCD Digit A single BCD digit is stored in the four least significant bits, and the upper four bits are set to 0. Decimal BCD 0 0000 1 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 0111 8 1000 9 1001 Continue…. Instruction Set in 8086 Arithmetic Instruction(Addition) 5. AAA : ASCII Adjust After Addition Case I : AL is between 0 to 9 & AF =0 After the addition, the AAA instruction examines the lower 4 bits of the AL to check whether it contain valid BCD number in the range 0-9. If it is b/w 0-9 then set four high order bit of AL to zero & AH must be cleared before addition. Eg MOV AX,32H ;AX=0032H MOV BX,35H ;BX=0035H ADD AX,BX ;AX=00 67H ;AX=0000 0000 0110 0111 (binary) AAA AH AL (set high order bit of AL to zero) Continue…. Perform AAA instruction such that AX=34H,BX=35H MOV AX,34 ; AX=0034H MOV BX,35 ;BX=0035H ADD AX,BX ;AX=00 69 AAA IGNORE 6 Correct answer after AAA instruction 09H Instruction Set in 8086 Arithmetic Instruction(Addition) 5. AAA : ASCII Adjust After Addition Case II: If the least significant four bit in AL are >9 or if AF =1,ADD 6 to AL & 1 to AH Both CF & AF are set The most significant four bit in AH should be cleared Higher four bit of AL are cleared to zero Eg MOV AX.36H ; AX=0036H MOV BX,34H ; BX=0034H ADD AX,BX ; AX=00 6AH AH AL AAA ADD 06 to AL & 01 to AH 6AH 00 + 06H +01 70H 01H Correct Answer 01 00 (ignore 7) Perform AAA instruction such that AX=64H,BX=48H MOV AX,64 ; AX=0064H MOV BX,48 ;BX=0048H ADD AX,BX ;AX=00 AC AAA ADD 06 to AL,01 to AH Correct answer after 0102H Instruction Set in 8086 Arithmetic Instruction(Addition) 6. DAA: Decimal adjust AL after addition This instruction is used to convert the result of addition of two BCD number to valid BCD number. The result has to be in AL ,if the lower nibble is greater than ‘9’,after addition or if ‘AF’ is set, it add 06H to lower nibble in AL. After adding 06H in the lower nibble of AL, if upper nibble of AL is greater than 9 or if the carry flag is set, DAA instruction adds 60H to AL. Instruction Set in 8086 Arithmetic Instruction(Addition) 6. DAA: Decimal adjust AL after addition Eg. AL =53H,CL=29H ADD AL,CL ;AL AL+CL ;AL7CH DAA ;AL7C + 06 ;AL82H Instruction Set in 8086 Arithmetic Instruction(Addition) 6. DAA: Decimal adjust AL after addition Perform DAA instruction given AL=73H CL=29H, ADD AL,CL ;AL 73H +29 H ;AL 9C 9C 12 DAA ;AL9C+ 06H +06 +6 A2 18(D)12H ;AL A2 & CF =1 ;AL A2 +60 H ;AL 02 CF =1 Instruction Set in 8086 Arithmetic Instruction(Subtraction) 7.SUB: Subtraction The subtraction instruction subtracts the source operand from the destination operand & the result is left in the destination operand 1.SUB AX,0100H 2.SUB AX,BX 3.SUB AX,[0500H] Instruction Set in 8086 Arithmetic Instruction(Subtraction) 8. SBB: Subtract with Borrow The subtract with borrow instruction subtract the source operand & the borrow flag which may reflect the result of the previous calculations, from the destination operand. Subtract with borrow means subtracting 1 from the subtraction obtained by SUB, if Carry flag is set. Eg SBB AX,0100H SBB AX,BX SBB AX,[5000H] SBB [5000H],0100 Instruction Set in 8086 Arithmetic Instruction 9. NEG: Negate The negate instruction forms 2’s complement of specified destination in the instruction -invert all the bits of the operand -add 1 to inverted operand Eg. MOV AL,05H ; AL05H NEG AL ;AL ?? 0FBH NEG AL ;AL ?? Instruction Set in 8086 Arithmetic Instruction(Subtraction) 10. AAS: ASCII Adjust AL after Subtraction AAS instruction corrects the result in AL register after subtracting two unpacked ASCII operands. The result is in unpacked decimal format if the lower four bits of AL are greater then 9 or AF are greater then 9 or AF is equal to 1 then -AL is decremented by 06H -AH is decremented by 01H -CF & AF are said to 1 -Clear the higher four bit of AL otherwise CF & AF are set to zero the result needs no correction Instruction Set in 8086 Arithmetic Instruction(Subtraction) 10. AAS: ASCII Adjust AL after Subtraction Eg. AX=006AH Step1 DEC AL by 06 6A - 06 64HAL Step 2 Dec AH by 01 00 - 01 FF H Instruction Set in 8086 Arithmetic Instruction(Subtraction) 11. DAS: Decimal adjust after Subtraction This instruction converts the result of subtraction of the two BCD numbers to valid BCD number. The subtraction has to be AL only. CASE I: If the lower nibble of AL is greater then 9,this instruction will subtract 06 from the lower nibble of AL CASE II: If the result of subtraction sets the carry flag or if upper nibble is greater than 9,it subtract 60H from AL Instruction Set in 8086 Arithmetic Instruction(Subtraction) 11. DAS: Decimal adjust after Subtraction Eg AL=75 ,BL = 46 SUB AL,BH ; AL 2F ;AF 1 DAS ;AL2 9(as F>9,F-6= 9) AL =38 CL =61 SUB AL,CL ;AL D7 CF=1(Borrow) ;AL77 (as D>9,D-6=7) ;CF =1(Borrow) Instruction Set in 8086 Arithmetic Instruction (Multiplication) 12.MUL: Unsigned Multiplication Byte or word IMUL: Signed Multiplication Byte or word It multiplies unsigned byte or word by the content of AL or AX. The unsigned byte or word may lie in any one of the general purpose register or memory location. If operand is byte then AL is multiplied with operant & result is stored in AX In case of 32 bit higher order word stored in DX, lower order word stored in AX register AX=AL * OPERAND Eg MOV AL,200 ; AL =C8H MOV BL,4 ;BL = 4H MUL BL ;AX= AL* BL=320H Instruction Set in 8086 Arithmetic Instruction (Multiplication) 14.AAM: ASCII adjust after Multiplication This instruction after execution, convert the product available in AL into unpacked BCD format. The AAM instruction replace content of AH by tens of the decimal multiplication & AL by single of decimal multiplication Eg. MOV AL,04 ; AL04 MOV BL,09 ;BL09 MUL BL ;AX24H AAM ; 3 6 (Decimal multiplication) TU AH 03,AL 06 03 06 14.AAM: ASCII adjust after Multiplication Eg. MOV BL,05H MOV AL,06H MUL BL ;AXAL*BL ;AX1EH AAM ;AX=0300H Instruction Set in 8086 Arithmetic Instruction 15.DIV: Unsigned Division/IDIV: Signed Division This instruction perform unsigned division. It divides unsigned word or double word by a 16 bit or 8 bit operant. The dividend must be in AX for 16 bit operation Result will be in AL (Quotient ) while AH will contain the remainder. Double word dividend(32 bit) the high word should be in DX & lower word should be in AX AL / CL AH AL DIVIDENT DIVISOR Remainder Quotient Instruction Set in 8086 Arithmetic Instruction 17.AAD: ASCII Adjust before Division The AAD instruction converts two unpacked BCD digits in AH & AL to the equivalent binary number in AL. The adjustment must be made before dividing the two unpacked BCD digits in AX by an unpacked BCD bytes Before dividing the unpacked BCD by another unpacked BCD, AAD is used to convert it to HEX. By doing that the quotient and reminder are both in unpacked BCD MOV CH,09H MOV AX,0607 ;AX=0607( Decimal) AAD ;AX=0067 ( AL= (AH*10)+AL ) & Clear AH=0 ;AX=0043H DIV CH EG 050252 (DECIMAL)AX=34H 17.AAD: ASCII Adjust before Division Eg. MOV AX,0307 H ; AX0307 H AAD ;AX=0025H MOV BL,05H ;BH05H DIV BL ;25/05gives AL=05H,AH=00H AX=0005H Instruction Set in 8086 Arithmetic Instruction (Multiplication) 18.CBW: Convert Signed Byte to Word This instruction covert a signed byte to a signed word 19.CWB: Convert Signed Word to Double Word This instruction copies the sign bit of AX to all the bits of the DX register. This operation is to be done before signed division. Example What is the result of executing the following sequence of instruction MOV AL,0A1H CBW CWD Solution The first instruction loads AL with A1H.This gives (AL)=A1H=1010 00012 Executing the second instruction extends the most significant bit of AL,1 into all bits of AH. The result is AH=1111 1111=FFH OR AX=1111 1111 1010 00012 =FFA1H This completes conversion of the byte in AL to a word in AX. The last instruction loads each bit of DX with the most significant bit of AX. This bit is also 1.Therefor,we get DX=1111 1111 1111 11112 = FFFFH Now the word in AX has been extended to double word. That is AX=FFA1H DX=FFFFH Q1. What operation is performed by each of the following instructions. a) ADD AX,OOFFH b) ADC SI,AX c) INC BYTE PTR[0100H] d) SUB DL,BL e) SBB DL,[0200H] f) MUL DX g) IMUL BYTE PTR[BX+SI] h) DIV BYTE PTR[SI]+0030H Q2. Write an instruction that will add the immediate value 111FH & the carry flag to the content of data Register DX. Q3. Write instruction that show two different ways to incrementing the address pointer in SI by two. Q4. If AL contain A0H.What happens when the instruction CBW is executed. Q5. If the value in AX is 7FFFFH ,what happens when the instruction CWD is executed. Q6.Write an instruction sequence that will initialize the ES register with the immediate value 1010H. Q7. What happen when the instruction MOV CL,AX is executed. Q8. Write a single instruction that loads AX from address 0200H & DS from address 0202H. Q9. What is the result of executing the following instruction sequence ADD AL,BL AAA Assume that AL contain 32H, BL contain 34H. Q10. What instruction is used to adjust the result of addition that processed packed BCD numbers. Program 1.Write a program in TASM to manipulate the two given operands with general arithmetic operators +, - and store the result at the given location. 2.Write a program in TASM to manipulate the two given operands with general arithmetic operators *, / and store the result at the given location. 3.Write a program for addition of two word size integer and store the result in DX register. 4.Write a well commented code to covert packed BCD into unpacked BCD.(i.e XY into 0X & 0Y) Refrence TEXT BOOKS: 1. Avtar Singh & Walter A. Triebel: The 8088 and 8086 Microprocessors, Programming, Interfacing, Software, Hardware, and Applications, PHI, fouth edition. Reference Book 2.A.K Ray & K.M BhurchandiAdance Microprocessor & Peripherals