Example: air traffic controller

Instruction set of 8086 Microprocessor - bsiet.org

1 Instruction set of Instruction set of 8086 Microprocessor8086 Microprocessor2 The sequence of commands used to tell a microcomputer what to do is called a program, Each command in a program is called an Instruction A program written in machine language is referred to as machine codeADD AX, BX(Opcode) (Destination operand) (Source operand )SoftwareSoftware3 InstructionsInstructionsLABEL: Instruction ; COMMENTA ddress identifier Does not generate any machine code Ex. START: MOV AX, BX ; copy BX into AX There is a one-to-one relationship between assembly and machine language instructions A compiled machine code implementation of a program written in a high-level language results in inefficient code More machine language instructions than an assembled version of an equivalent handwritten assembly language program4 Two key benefits of assembly language programming It takes up less memory It executes much faster5 ApplicationsApplications One of the most beneficial uses of assembly language programming is real-time time means the task required by the application must be completed before any other input to the program that will alter its operation can occur For example the device service routine which controls the operation of the floppy disk drive is a good example that is usually written in assembly language6 Assembly language not only good for contr

2 • The sequence of commands used to tell a microcomputer what to do is called a program, • Each command in a program is called an instruction • A program written in machine language is referred to as machine code ADD AX, BX (Opcode) (Destination operand) (Source operand ) …

Tags:

  Instructions, Sequence, The sequence

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Transcription of Instruction set of 8086 Microprocessor - bsiet.org

1 1 Instruction set of Instruction set of 8086 Microprocessor8086 Microprocessor2 The sequence of commands used to tell a microcomputer what to do is called a program, Each command in a program is called an Instruction A program written in machine language is referred to as machine codeADD AX, BX(Opcode) (Destination operand) (Source operand )SoftwareSoftware3 InstructionsInstructionsLABEL: Instruction ; COMMENTA ddress identifier Does not generate any machine code Ex. START: MOV AX, BX ; copy BX into AX There is a one-to-one relationship between assembly and machine language instructions A compiled machine code implementation of a program written in a high-level language results in inefficient code More machine language instructions than an assembled version of an equivalent handwritten assembly language program4 Two key benefits of assembly language programming It takes up less memory It executes much faster5 ApplicationsApplications One of the most beneficial uses of assembly language programming is real-time time means the task required by the application must be completed before any other input to the program that will alter its operation can occur For example the device service routine which controls the operation of the floppy disk drive is a good example that is usually written in assembly language6 Assembly language not only good for controlling hardware devices but

2 Also performing pure software operations Searching through a large table of data for a special string of characters Code translation from ASCII to EBCDIC Table sort routines Mathematical routinesAssembly language: perform real-time operationsHigh-level languages: used to write those parts that are not time critical7 Converting Assembly Language instructions to Machine Code An Instruction can be coded with 1 to 6 bytes Byte 1 contains three kinds of information Opcode field (6 bits) specifies the operation (add, subtract, move) Register Direction Bit (D bit) Tells the register operand in REG field in byte 2 is source or destination operand1: destination 0: source- Data Size Bit (W bit) Specifies whether the operation will be performed on 8-bit or 16-bit data 0: 8 bits 1: 16 bits8 Byte 2 has three fields Mode field (MOD) Register field (REG) used to identify the register for the first operand Register/memory field (R/M field)9 MnemonicMeaningFormatOperation Flags affected MOV Move Mov D,S(S) (D)None Data Transfer instructions - MOVData Transfer instructions - MOVD estination Source Memory Accumulator Accumulator Memory Register Register Register Memory Memory Register Register Immediate Memory ImmediateSeg regReg 16 Seg regMem 16 Reg 16 Seg reg Memory Seg reg NO MOVM emoryImmediateSegment RegisterMemorySegment RegisterSegment RegisterEX:MOV AL, BL10 Data Transfer instructions - XCHGData Transfer instructions - XCHGM nemonicMeaningFormatOperation Flags affected XCHGE xchange XCHG D,S(S) (D)None Destination Source Accumulator Reg 16 Memory Register Register Register Register Memory Example.

3 XCHG START [BX]NO XCHG MEMsSEG REGs11 Data Transfer instructions LEA, LDS, LESM nemonicMeaningFormatOperation Flags affected LEALoad Effective Address LEA Reg16,EAEA (Reg16)NoneLDSLoad Register And DS LDS Reg16,MEM(MEM) (Reg16)(Mem+2) (DS)NoneLESLoad Register and ES LES Reg16,MEM(MEM) (Reg16)(Mem+2) (ES)None LEA SI DATA (or) MOV SI Offset DATA12 The XLAT InstructionThe XLAT InstructionMnemonicMeaningFormatOperatio nFlagsXLATT ranslateXLAT((AL)+(BX)+(DS)0) (AL)NoneExample: Assume (DS) = 0300H, (BX)=0100H, and (AL)=0 DHXLAT replaces contents of AL by contents of memory location with PA=(DS)0 +(BX) +(AL) = 03000H + 0100H + 0DH = 0310 DHThus(0310DH) (AL)13 Arithmetic instructions : ADD, ADC, INC, AAA, DAAM nemonicMeaningFormatOperation Flags affected ADDA ddition ADD D,S(S)+(D) (D) carry (CF)ALLADCAdd with carryADC D,S(S)+(D)+(CF) (D) carry (CF)ALLINCI ncrement by one INC D(D)+1 (D) ALL but CYAAAASCII adjust for additionAAAA fter addition AAA Instruction is used to make sure the result is the correct unpacked BCDAF,CFDAAD ecimal adjust for addition DAAA djust AL for decimalPacked BCDALL14 ADD AX,2 ADC AX,2 INC BX INC WORD PTR [BX] ASCII CODE 0-9 = 30-39h ADD CL,DL; [CL]=32=ASCII FOR 2 ; [DL]=35=ASCII FOR 5; RESULT[CL]=67 MOV AL,CL;Move the ascii result into AL since AAA adjust only [AL] AAA;[AL]=07, unpacked BCD for 7.

4 15 Arithmetic instructions SUB, SBB, DEC, AAS, DAS, NEGM nemonicMeaningFormatOperation Flags affected SUBS ubtract SUB D,S(D) - (S) (D) Borrow (CF)AllSBBS ubtract with borrowSBB D,S(D) - (S) - (CF) (D) AllDECD ecrement by one DEC D (D) - 1 (D) All but CFNEGN egateNEG DAllDASD ecimal adjust for subtractionDASC onvert the result in AL to packed decimal formatAllAASASCII adjust for subtraction AAS(AL) difference(AH) dec by 1 if borrowCY,AC16 Multiplication and Division17 Multiplication and Division18 Multiplication(MUL or IMUL)MultiplicandOperand(Multiplier)Resu ltByte*ByteALRegister or memoryAXWord*WordAXRegister or memoryDX :AXDword*DwordEAXR egister or memoryEAX :EDXD ivision (DIV or IDIV)Dividend Operand (Divisor)Quotient: RemainderWord/ByteAXRegister or MemoryAL : AHDword/WordDX:AXRegister or MemoryAX : DXQword/DwordEDX: EAXR egister or MemoryEAX : EDX Multiplication and Division19 Multiplication and Division ExamplesEx1:Assume that each Instruction starts from these values:AL = 85H, BL = 35H, AH = 0H 1.

5 MUL BL AL . BL = 85H * 35H = 1B89H AX = 1B89H 2. IMUL BL AL . BL = 2 S AL * BL = 2 S (85H) * 35H = 7BH * 35H = 1977H 2 s comp E689H AX. DIV BL = = 02 (85-02*35=1B) 4. IDIV BL = = 1 BHH35008502 AHALBLAXBLAXHH3500851B02 AHAL20Ex2: AL = F3H, BL = 91H, AH = BL AL * BL = F3H * 91H = 89A3H AX = 89A3H BL AL * BL = 2 S AL * 2 S BL = 2 S (F3H) * 2 S(91H) = 0DH * 6FH = 05A3H AX. BL = = = 2 (00F3 2*6F=15H)BLAX)91('2300 HSHFFHHF6300AH AL15 02 R QNEGNEGPOS= 2 s(02) = FEH AH AL15 FE 4. DIV BL = = 01 (F3-1*91=62) BLAXHHF91300AH AL62 01 R Q21Ex3:AX= F000H, BX= 9015H, DX= 0000H 1. MUL BX = F000H * 9015H = DX AX8713B0002. IMUL BX = 2 S(F000H) * 2 S(9015H) = 1000 * 6 FEB =DX AX06 FEB0003. DIV BL = = B6DH More than FFH Divide Error.

6 HHF150004. IDIV BL = = C3H > 7F Divide Error. HHFS15)000('2HH15100022Ex4:AX= 1250H, BL= 90H 1. IDIV BL = = = = = BLAXHH901250 NEGPOSsNEGPOS'2)90('21250 HsHHH701250 = 29H (Q) (1250 29 * 70) = 60H (REM) 29H ( POS) 2 S (29H) = D7H R Q60HD7H 2. DIV BL = = 20H 1250-20*90 =50H BLAXHH901250R Q50H 20H AH AL23 MnemonicMeaningFormat OperationFlags AffectedAND ORXORNOTL ogical ANDL ogical Inclusive ORLogical Exclusive ORLOGICAL NOT AND D,SOR D,SXOR D,SNOT D(S) (D) (D) (S)+(D) (D)(S) (D) (D)_ (D) (D)OF, SF, ZF, PF, CFAF undefinedOF, SF, ZF, PF, CFAF undefinedOF, SF, ZF, PF, CFAF undefinedNone+Logical InstructionsDestinationSourceRegisterReg isterMemoryRegisterMemoryAccumulatorRegi sterMemoryRegisterImmediateImmediateImme diateDestinationRegister Memory24 LOGICAL instructions AND Uses any addressing mode except memory-to-memory and segment registers Especially used in clearing certain bits (masking) xxxx xxxx AND 0000 1111 = 0000 xxxx (clear the first four bits) Examples.

7 AND BL, 0 FHAND AL, [345H] OR Used in setting certain bitsxxxx xxxx OR 0000 1111 = xxxx 1111(Set the upper four bits)25 XOR Used in Inverting bits xxxx xxxx XOR 0000 1111 = xxxxx x x x -Example: Clear bits 0 and 1, set bits 6 and 7, invert bit 5 of register CL:AND CL, OFCH; 1111 1100 BOR CL, 0C0H; 1100 0000 BXOR CL, 020H; 0010 0000B26 Shift and Rotate instructions SHR/SAL: shift logical left/shift arithmetic left SHR: shift logical right SAR: shift arithmetic right ROL: rotate left ROR: rotate right RCL: rotate left through carry RCR: rotate right through carry27 Logical vs Arithmetic Shifts A logical shift fills the newly created bit position with zero: An arithmetic shift fills the newly created bit position with a copy of the number s sign bit:28 Mnemo-nicMeaningFormatOperation Flags AffectedSAL/SHLSHRSARS hift arithmeticLeft/shiftLogical leftShift logical rightShift arithmeticright SAL/SHL D, CountSHR D, CountSAR D, CountShift the (D) left by the number of bit positions equal to count and fill the vacated bits positions on the right with zerosShift the (D) right by the number of bit positions equal to count and fill the vacated bits positions on the left with zerosShift the (D) right by the number of bit positions equal to count and fill the vacated bits positions on the left with the original most significant bitCF,PF,SF,ZFAF undefinedOF undefined if count 1CF,PF,SF,ZFAF undefinedOF undefined if count 1CF,PF,SF,ZFAF undefinedOF undefined if count 1 Shift Instructions29 Allowed operandsDestinationCountRegister Register Memory Memory1CL1CL30 31 SHL Instruction The SHL (shift left)

8 Instruction performs a logical left shift on the destination operand, filling the lowest bit with 0. Operand types:SHL reg,imm8 SHL mem,imm8 SHL reg,CLSHL mem,CL32 Fast Multiplicationmov dl,5shl dl,1 Shifting left 1 bit multiplies a number by 2mov dl,5shl dl,2; DL = 20 Shifting left n bits multiplies the operand by 2nFor example, 5 * 22 = 2033Ex.; Multiply AX by 10 SHL AX, 1 MOV BX, AXMOV CL,2 SHL AX,CLADD AX, BX34 SHR Instruction The SHR (shift right) Instruction performs a logical right shift on the destination operand. The highest bit position is filled with a DL,80 SHR DL,1; DL = 40 SHR DL,2; DL = 10 Shifting right n bits divides the operand by 2n35 SAR Instruction SAR (shift arithmetic right) performs a right arithmetic shift on the destination arithmetic shift preserves the number's DL,-80 SAR DL,1; DL = -40 SAR DL,2; DL = -1036 Rotate InstructionsRotate InstructionsMnem-onicMeaningFormatOperat ionFlags AffectedROLR otate LeftROL D,CountRotate the (D) left by the number of bit positions equal to Count.

9 Each bit shifted out from the left most bit goes back into the rightmost bit OF undefined if count 1 RORR otate RightROR D,CountRotate the (D) right by the number of bit positions equal to Count. Each bit shifted out from the rightmost bit goes back into the leftmost bit OF undefined if count 1 RCLR otate Left through CarryRCL D,CountSame as ROL except carry is attached to (D) for OF undefined if count 1 RCRR otate right through CarryRCR D,CountSame as ROR except carry is attached to (D) for OF undefined if count 137 ROL Instruction ROL (rotate) shifts each bit to the left The highest bit is copied into both the Carry flag and into the lowest bit No bits are lostMOV Al,11110000bROL Al,1; AL = 11100001bMOV Dl,3 FhROL Dl,4; DL = F3h38 ROR Instruction ROR (rotate right) shifts each bit to the right The lowest bit is copied into both the Carry flag and into the highest bit No bits are lostMOV AL,11110000bROR AL,1; AL = 01111000bMOV DL,3 FhROR DL,4; DL = F3h39 RCL Instruction RCL (rotate carry left) shifts each bit to the left Copies the Carry flag to the least significant bit Copies the most significant bit to the Carry flagCFCLC.

10 CF = 0 MOV BL,88H; CF,BL = 0 10001000bRCL BL,1; CF,BL = 1 00010000bRCL BL,1; CF,BL = 0 00100001b40 RCR Instruction RCR (rotate carry right) shifts each bit to the right Copies the Carry flag to the most significant bit Copies the least significant bit to the Carry flagSTC; CF = 1 MOV AH,10H; CF,AH = 00010000 1 RCR AH,1; CF,AH = 10001000 041 DestinationCountRegister Register Memory Memory1CL1 CLRotate Instructions42 Flag control instructionsMNEM-ONICMEANINGOPERATIONF lags AffectedCLCC lear Carry Flag(CF) 0 CFSTCSet Carry Flag(CF) 1 CFCMCC omplement Carry Flag(CF) (CF)lCFCLDC lear Direction Flag(DF) 0SI & DI will be auto incremented while string instructions are Direction Flag(DF) 1SI & DI will be auto decremented while string instructions are Interrupt Flag(IF) 0 IFSTISet Interrupt Flag(IF) 1IF43 Compare Instruction , CMPM nemonicMeaningFormatOperationFlags AffectedCMPC ompareCMP D,S(D) (S) is used in setting or resetting the flagsCF, AF, OF, PF, SF, ZF(D) = (S); ZF=0(D) > (S) ; ZF=0, CF=0(D) < (S) ; ZF=0, CF=1 Allowed OperandsDestinationSourceRegisterRegiste rRegisterMemoryMemoryRegisterRegisterImm ediateMemoryImmediateAccumulatorImmediat e44 String?


Related search queries