1 / 67

Instruction Set of 8086

Instruction Set of 8086. K.Praveen Kumar Asst. Professor GITAM University. Instruction Set of 8086. An instruction is a binary pattern designed inside a microprocessor to perform a specific function. The entire group of instructions that a microprocessor supports is called Instruction Set .

mhuston
Télécharger la présentation

Instruction Set of 8086

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Instruction Set of 8086 K.Praveen Kumar Asst. Professor GITAM University

  2. Instruction Set of 8086 • An instruction is a binary pattern designed inside a microprocessor to perform a specific function. • The entire group of instructions that a microprocessor supports is called Instruction Set. • 8086 has more than 20,000 instructions.

  3. Classification of Instruction Set • Data Transfer Instructions • Arithmetic Instructions • Logical Instructions • Program Control Transfer or Branching Instructions • String Instructions • Processor Control Instructions

  4. Data Transfer Instructions • These instructions are used to transfer data from source to destination. • The operand can be a constant, memory location, register or I/O port address.

  5. Data Transfer Instructions • MOV Des, Src: • Src operand can be register, memory location or immediate operand. • Des can be register or memory operand. • Both Src and Des cannot be memory location at the same time. • E.g.: • MOV CX, 037A H • MOV AL, BL • MOV BX, [0301 H]

  6. Data Transfer Instructions • PUSH Operand: • It pushes the operand into top of stack. • The operand can be a general purpose register or segment registers or memory location. • E.g.: PUSH BX • POP Des: • It pops the operand from top of stack to Des. • Des can be a general purpose register, segment register (except CS) or memory location. • E.g.: POP AX

  7. Data Transfer Instructions • XCHG Des, Src: • This instruction exchanges Src with Des. • It cannot exchange two memory locations directly. • E.g.: XCHG DX, AX • E.g.: XCHG DX, [SI] • E.g.: XCHG [DI], AX

  8. Data Transfer Instructions • IN Accumulator, Port Address: • It transfers the operand from specified port to accumulator register. • E.g.: IN AX, 0028 H • E.g.: IN AL, 28 H • E.g.: IN AL, DX • E.g.: IN AX, DX

  9. OUT Port Address, Accumulator: • It transfers the operand from accumulator to specified port. • E.g.: OUT DX, AX • E.g.: OUT 32H, AL • E.g.: OUT DX, AL • E.g.: OUT 0028 H, AX • E.g.: OUT 45H, AL

  10. Data Transfer Instructions • LDS Des, Src: • It loads 32-bit pointer from memory source to destination register and DS. • The offset is placed in the destination register and the segment is placed in DS. • To use this instruction the word at the lower memory address must contain the offset and the word at the higher address must contain the segment. • E.g.: LDS BX, [DI]

  11. Data Transfer Instructions • LES Des, Src: • It loads 32-bit pointer from memory source to destination register and ES. • The offset is placed in the destination register and the segment is placed in ES. • This instruction is very similar to LDS except that it initializes ES instead of DS. • E.g.: LES DI, [BX]

  12. Data Transfer Instructions • LEA Register, Src: • It loads a 16-bit register with the offset address of the data specified by the Src. • E.g.: LEA BX, [DI] • This instruction loads the contents of DI (offset) into the BX register.

  13. Data Transfer Instructions • LAHF: • It copies the lower byte of flag register to AH. • SAHF: • It copies the contents of AH to lower byte of flag register. • PUSHF: • Pushes flag register to top of stack. • POPF: • Pops the stack top to flag register.

  14. Data Transfer Instructions • XLAT: Translate Byte to AL • The translate instruction is used for finding out the codes in case of code conversion problems, using look up table technique.

  15. Arithmetic Instructions • ADD Des, Src: • It adds a byte to byte or a word to word. • It effects AF, CF, OF, PF, SF, ZF flags. • E.g.: • ADD AL, 74H • ADD DX, AX • ADD AX, [BX]

  16. Arithmetic Instructions • ADC Des, Src: • It adds the two operands with CF. • It effects AF, CF, OF, PF, SF, ZF flags. • E.g.: • ADC AL, 74H • ADC DX, AX • ADC AX, [BX]

  17. Arithmetic Instructions • SUB Des, Src: • It subtracts a byte from byte or a word from word. • It effects AF, CF, OF, PF, SF, ZF flags. • For subtraction, CF acts as borrow flag. • E.g.: • SUB AL, 74H • SUB DX, AX • SUB AX, [BX]

  18. Arithmetic Instructions • SBB Des, Src: • It subtracts the two operands and also the borrow from the result. • It effects AF, CF, OF, PF, SF, ZF flags. • E.g.: • SBB AL, 74H • SBB DX, AX • SBB AX, [BX]

  19. Arithmetic Instructions • INC Src: • It increments the byte or word by one. • The operand can be a register or memory location. • It effects AF, OF, PF, SF, ZF flags. • CF is not effected. • E.g.: INC AX

  20. Arithmetic Instructions • DEC Src: • It decrements the byte or word by one. • The operand can be a register or memory location. • It effects AF, OF, PF, SF, ZF flags. • CF is not effected. • E.g.: DEC AX

  21. Arithmetic Instructions • NEG Src: • It creates 2’s complement of a given number. • That means, it changes the sign of a number.

  22. Arithmetic Instructions • CMP Des, Src: • It compares two specified bytes or words. • The Src and Des can be a constant, register or memory location. • Both operands cannot be a memory location at the same time. • The comparison is done simply by internally subtracting the source from destination. • The value of source and destination does not change, but the flags are modified to indicate the result.

  23. Arithmetic Instructions • MUL Src: • It is an unsigned multiplication instruction. • It multiplies two bytes to produce a word or two words to produce a double word. • AX = AL * Src • DX : AX = AX * Src • This instruction assumes one of the operand in AL or AX. • Src can be a register or memory location. • IMUL Src: • It is a signed multiplication instruction.

  24. Arithmetic Instructions • DIV Src: • It is an unsigned division instruction. • It divides word by byte or double word by word. • The operand is stored in AX, divisor is Src and the result is stored as: • AH = remainder AL = quotient • IDIV Src: • It is a signed division instruction.

  25. Arithmetic Instructions • CBW (Convert Byte to Word): • This instruction converts byte in AL to word in AX. • The conversion is done by extending the sign bit of AL throughout AH. • CWD (Convert Word to Double Word): • This instruction converts word in AX to double word in DX : AX. • The conversion is done by extending the sign bit of AX throughout DX.

  26. Representation of Numbers • ASCII representation • Numbers are stored as a string of ASCII characters • Example: 1234 is stored as 31 32 33 34H • ASCII for 1 is 31H, for 2 is 32H, etc. • BCD representation • Unpacked BCD • Example: 1234 is stored as 01 02 03 04H • Additional byte is used for sign • Sign byte: 00H for + and 80H for - • Packed BCD • Saves space by packing two digits into a byte • Example: 1234 is stored as 12 34H

  27. Arithmetic Instructions • DAA (Decimal Adjust after Addition) • It is used to make sure that the result of adding two BCD numbers is adjusted to be a correct BCD number. • It only works on AL register. • DAS (Decimal Adjust after Subtraction) • It is used to make sure that the result of subtracting two BCD numbers is adjusted to be a correct BCD number. • It only works on AL register.

  28. Processing Packed BCD Numbers Packed BCD addition Example 1 Example 2 29H = 00101001B 27H = 00100111B 69H = 01101001B 34H = 00110100B 92H = 10010010B 5BH = 01011101B Should be 98H (add 6) Should be 61H (add 6) Example 3 52H = 01010010B 61H = 01100001B B3H = 10110010B Should be 13H (add 60H)

  29. Processing Packed BCD Numbers • The daa instruction works as follows: • If the least significant four bits in AL are > 9 or if AF =1, it adds 6 to AL and sets AF • If the most significant four bits in AL are > 9 or if CF =1, it adds 60H to AL and sets CF Example: mov AL,71H add AL,43H ; AL = B4H daa ; AL = 14H and CF = 1 • The result including the carry (i.e., 114H) is the correct answer

  30. Processing Packed BCD Numbers Packed BCD subtraction • The das instruction works as follows: • If the least significant four bits in AL are > 9 or if AF =1, it subtracts 6 from AL and sets AF • If the most significant four bits in AL are > 9 or if CF =1, it subtracts 60H from AL and sets CF Example: mov AL,71H sub AL,43H ; AL = 2EH das ; AL = 28H

  31. Representation of Numbers • Numbers are in ASCII form • when received from keyboard • when sending to the display • Binary form is efficient to process numbers internally

  32. Arithmetic Instructions • AAA (ASCII Adjust after Addition): • The data entered from the terminal is in ASCII format. • In ASCII, 0 – 9 are represented by 30H – 39H. • This instruction allows us to add the ASCII codes. • This instruction does not have any operand. • Other ASCII Instructions: • AAS (ASCII Adjust after Subtraction) • AAM (ASCII Adjust after Multiplication) • AAD (ASCII Adjust Before Division)

  33. Processing ASCII Numbers ASCII addition Example 1 Example 2 34H = 00110100B 36H = 00110110B 35H = 00110101B 37H = 00110111B 69H = 01101001B 6DH = 01101101B Should be 09H Should be 13H Ignore 6 Ignore 6 and add 6 to D • The aaa instruction performs these adjustments to the byte in AL register

  34. Processing ASCII Numbers • The aaa instruction works as follows: • If the least significant four bits in AL are > 9 or if AF =1, it adds 6 to AL and 1 to AH. • Both CF and AF are set • In all cases, the most significant four bits in AL are cleared • Example: sub AH,AH ; clear AH mov AL,‘36' ; AL = 36H add AL,‘37' ; AL = 36H+37H = 6DH aaa ; AX = 0103H or AL,30H ; AL = 33H

  35. Processing ASCII Numbers ASCII subtraction • The aas instruction works as follows: • If the least significant four bits in AL are > 9 or if AF =1, it subtracts 6 from AL and 1 from AH. • Both CF and AF are set • In all cases, the most significant four bits in AL are cleared • This adjustment is needed only if the result is negative

  36. Processing ASCII Numbers • Example 1: sub AH,AH ; clear AH mov AL,‘39' ; AL = 39H sub AL,‘33' ; AL = 39H-33H = 6H aas ; AX = 0006H or AL,30H ; AL = 36H

  37. Processing ASCII Numbers ASCII multiplication • The aam instruction adjusts the result of a mul instruction • Multiplication should not be performed on ASCII • Can be done on unpacked BCD • The aam instruction works as follows • AL is divided by 10 • Quotient is stored in AH • Remainder in AL • aam does not work with imul instruction

  38. Processing ASCII Numbers • Example 1 mov AL,03 ; multiplier in unpacked BCD form mov BL,09 ; multiplicand in unpacked BCD form mul BL ; result 001BH is in AX aam ; AX = 0207H or AX,3030H ; AX = 3237H • Example 2 mov AL,‘33' ; multiplier in ASCII mov BL,‘39' ; multiplicand in ASCII and AL,0FH ; multiplier in unpacked BCD form and BL,0FH ; multiplicand in unpacked BCD form mul BL ; result 001BH is in AX aam ; AX = 0207H or AL,30H ; AL = 37H

  39. Processing ASCII Numbers ASCII division • The aad instruction adjusts the numerator in AX before dividing two unpacked decimal numbers • The denominator is a single unpacked byte • The aad instruction works as follows • Multiplies AH by 10 and adds it to AL and sets AH to 0 • Example: • If AX is 0207H before aad • AX is changed to 001BH after aad • aad instruction reverses the changes done by aam

  40. Processing ASCII Numbers • Example: Divide 27 by 5 mov AX,0207H ; dividend in unpacked BCD form mov BL,05H ; divisor in unpacked BCD form aad ; AX = 001BH div BL ; AX = 0205H • aad converts the unpacked BCD number in AX to binary form so that div can be used

  41. Logical Instructions • These instructions are used at the bit level. • These instructions can be used for: • Testing a zero bit • Set or reset a bit • Shift bits across registers

  42. Logical Instructions • NOT : Logical Invert Src • It complements each bit of Src to produce 1’s complement of the specified operand. • The operand can be a register or memory location. • Ex: NOT AX

  43. Logical Instructions • AND: Logical AND Des, Src: • It performs AND operation of Des and Src. • Src can be immediate number, register or memory location. • Des can be register or memory location. • Both operands cannot be memory locations at the same time. • CF and OF become zero after the operation. • PF, SF and ZF are updated. • Ex: AND AL, OFH

  44. Logical Instructions • OR: Logical OR Des, Src: • It performs OR operation of Des and Src. • Src can be immediate number, register or memory location. • Des can be register or memory location. • Both operands cannot be memory locations at the same time. • CF and OF become zero after the operation. • PF, SF and ZF are updated. • Ex: OR AL, OFH

  45. Logical Instructions • XOR: Logical Exclusive OR Des, Src: • It performs XOR operation of Des and Src. • Src can be immediate number, register or memory location. • Des can be register or memory location. • Both operands cannot be memory locations at the same time. • CF and OF become zero after the operation. • PF, SF and ZF are updated.

  46. Logical Instructions • SHL/SAL: Shift Logical/Arithmetic Left Des, Count: • It shift bits of byte or word left, by count. • It puts zero(s) in LSBs. • MSB is shifted into carry flag. • If the number of bits desired to be shifted is 1, then the immediate number 1 can be written in Count. • However, if the number of bits to be shifted is more than 1, then the count is put in CL register.

  47. Logical Instructions • SHR: Shift Logical right Des, Count: • It shift bits of byte or word right, by count. • It puts zero(s) in MSBs. • LSB is shifted into carry flag. • If the number of bits desired to be shifted is 1, then the immediate number 1 can be written in Count. • However, if the number of bits to be shifted is more than 1, then the count is put in CL register.

  48. Logical Instructions • SAR: Shift arithmetic Right Des, Count: • It shift bits of byte or word right, by count. • It puts the most significant bit of the operand in newly inserted positions.. • LSB is shifted into carry flag. • If the number of bits desired to be shifted is 1, then the immediate number 1 can be written in Count. • However, if the number of bits to be shifted is more than 1, then the count is put in CL register.

  49. Logical Instructions • ROL: Rotate Left Without Carry Des, Count: • It rotates bits of byte or word left, by count. • MSB is transferred to LSB and also to CF. • If the number of bits desired to be shifted is 1, then the immediate number 1 can be written in Count. • However, if the number of bits to be shifted is more than 1, then the count is put in CL register. Ex 1: ROL CX, 1 EX 2: MOV CL,03 ROL BL,CL

  50. Logical Instructions • ROR: Rotate Right Without Carry Des, Count: • It rotates bits of byte or word right, by count. • LSB is transferred to MSB and also to CF. • If the number of bits desired to be shifted is 1, then the immediate number 1 can be written in Count. • However, if the number of bits to be shifted is more than 1, then the count is put in CL register. Ex 1: ROR CX, 1 EX 2: MOV CL,03 ROR BL,CL

More Related