Mpmc u2 ece_arun


Published on

Microprocessors and Microcontrollers

Published in: Education
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Mpmc u2 ece_arun

  2. 2. Features of 8086 Microprocessor  It is a16-bit microprocessor.  It has a 20 bit address bus can access up to 220 Memory locations (1 MB).  It can support up to 64K I/O ports  It provides fourteen 16 -bit registers.  It has multiplexed address and data bus AD0- AD15 & A16 – A19.  It is designed to operate in 2 modes, Minimum and Maximum mode  It can prefetches up to 6 instruction bytes from memory and queues them in order to speed up instruction execution  It requires +5v power supply  It is a 40 pin dual in line package .M.M. Arun Prasath., AP/ECE 2
  3. 3. Programmers model of 8086 .M.M. Arun Prasath., AP/ECE 3
  4. 4. Operand Types of 8086 The 8086 supports the following types of operand 1. 2. 3. 4. 5. 6. 7. Bytes (8-bit) Words (16-bit) Short integers (8-bit) Integers (16-bit) Double words (32-bit) Long integers (32-bit) Strings (Series of alphanumeric characters defined by ASCII codes) .M.M. Arun Prasath., AP/ECE 4
  5. 5. Operand Addressing Addressing mode indicates a way of locating data or operands, We can classify the addressing modes of 8086 into 6 groups:  Register addressing mode  Immediate addressing mode  Memory addressing mode  Port addressing mode  Relative addressing mode  Implied addressing mode .M.M. Arun Prasath., AP/ECE 5
  6. 6. ADDRESSING MODES of 8086 1. Register Addressing Mode: 8086 CPU contains 8 General-Purpose Registers or Working Registers AX,BX,CX,DX,BP,DI,SI,SP and 4 Segment Registers CS,DS,ES,SS Source Registers: AX,BX,CX,DX,DI,SI,BP,SP,CS,DS,ES,SS Destination Registers: AX,BX,CX,DX,DI,SI,BP,SP, DS,ES,SS Ex.1: MOV AL,CL Ex.2: MOV DS,SI 2. Immediate Addressing Mode: 8 or 16 bit data can be specified as part of the instruction Ex: MVI AL,34H MVI SI,1212H .M.M. Arun Prasath., AP/ECE 6
  7. 7. ADDRESSING MODES of 8086 3. Memory addressing mode  One of the operands is in memory  8086 must use  a segment register  a 16-bit offset (effective address)  By default, DS register is used for accessing data from memory  16-bit offset can be specified in many ways 1. Direct Addressing mode 2. Register Indirect or Indirect Addressing mode 3. Base plus index Addressing mode 4. Register Relative Addressing mode 5. Base Relative plus Index Addressing mode 6. String Addressing mode .M.M. Arun Prasath., AP/ECE cont…7
  8. 8. ADDRESSING MODES of 8086 3. Memory addressing mode 1. Direct addressing mode Ex: MOV AL, DS MOV DS, DL MOV AX, DS .M.M. Arun Prasath., AP/ECE cont…8
  9. 9. ADDRESSING MODES of 8086 3. Memory addressing mode 2. Register Indirect or Indirect Addressing mode • In this mode, the Effective Address is specified in either a pointer register (BX or BP) or an index register (SI or DI). Ex: MOV BX,[CX] ;DS=10000H CX=2000H ;Physical Address: 12000H=30 ;BX=4030H 12001H=40 BH=40H BL=30H 3. Base plus index Addressing mode Ex: MOV CX,[BX+DI] ;DS=10000H BX=2000H DI=0030H ;Physical Address: 12030H=20 12031H=10 ;CX=1020H CH=10H CL=20H .M.M. Arun Prasath., AP/ECE cont…9
  10. 10. ADDRESSING MODES of 8086 3. Memory addressing mode 4. Register Relative Addressing mode CH CL CX Ex: MOV CX,[BX+0003H] ;DS=10000H BX=1000H ;Displacement=3 Base+Disp=1003H ;11003H=30H 11004H=40H ;CX=4030H CH=40H CL=30H 10 cont… .M.M. Arun Prasath., AP/ECE
  11. 11. ADDRESSING MODES of 8086 3. Memory addressing mode 5. Base Relative plus Index Addressing mode Ex: MOV AL,[BX+SI+10H] .M.M. Arun Prasath., AP/ECE 11 cont…
  12. 12. ADDRESSING MODES of 8086 3. Memory addressing mode 6. String Addressing mode • Used when string related instructions are executed. It uses index registers. • The string instructions automatically assumes SI to point the first byte or word of the source operand and DI to point the first byte or word of the destination operand. Ex: MOVS BYTE initially: [DF]=0 [DS]=30000H [ES]=50000H 30600H=38H after execution: 50400H=38H [SI]=0601H [SI]=0600H [DI]=0400H 50400H=45H [DI]=0401H .M.M. Arun Prasath., AP/ECE 12
  13. 13. ADDRESSING MODES of 8086 4. Port addressing Two I/O port addressing modes can be used Direct (e.g. IN AL, 02H) Indirect (e.g. IN AL, DXH) 5. Relative addressing Ex: JNC 08H ;IF carry = 0, PC is loaded with current PC contents + 8-bit signed value 6. Implied addressing mode No operands are specified Ex: CLC ;Means clear carry flag .M.M. Arun Prasath., AP/ECE 13
  14. 14. Assembler Directives of 8086  Assembler is a program which converts assembly language to machine language.  Syntax errors, logical errors and other program errors are not found out by the assembler.  For completing all these tasks the assembler needs some hints from the program, called Assembler Directives these hints are given to the assembler using some predefined alphabetical strings 1. ASSUME: The directive is used to inform the assembler the names of the logical segment which are to be assigned to the different segments used in an assembly language program 2. DB (Define Byte): It defines a byte type variable which occupies 1byte of memory space. .M.M. Arun Prasath., AP/ECE 14
  15. 15. Assembler Directives of 8086 3. DW (Define Word): It defines a word type variable which occupies 2bytes of memory space. 4. DD (Define Double Word): It defines a double word type variable which occupies 4bytes of memory space. 5. DQ (Define Quad Word): It defines a quad word type variable which occupies 8bytes of memory space. 6. DT (Define Ten Bytes): It defines a variable which occupies 10bytes of memory space. 7. END (End of Program): It informs assembler the end of program module. 8. ENDP (End Procedure): It informs assembler the end of procedure (subroutines) 9. ENDM (End Macro): It informs assembler the end of the macro. It used with the directive MACRO to enclose macro instructions. 10. ENDS (End Segment): It informs assembler that it is the end of a segment. .M.M. Arun Prasath., AP/ECE 15
  16. 16. Assembler Directives of 8086 11. EQU (Equate): It is used to give a name to certain value or symbol which is used many times in an assembly language program to make programming easy. 12. EVEN (Align or Even memory address): It informs assembler to increment the content of the location counter to the next memory address, if it is already no at an even address. 13. EXTRN (External): It informs that the names, procedures and labels following this directive have already been defined in some other program module. 14. GLOBAL: It can be used in place of public or external directive. 15. GROUP: It informs assembler to form a logical group of the segments named after this directive. 16. INCLUDE (Include source code from file): It informs assembler to insert a block of codes from a named file in to the current program module. It is convenient to keep all data and macros in a file called header file or include file. .M.M. Arun Prasath., AP/ECE 16
  17. 17. Assembler Directives of 8086 17. LABEL: In assembly language program, labels are used to give names to memory addresses. 18. LENGTH: It is an operator to determine the no. of elements in a data item such as an array or a string. 19. LOCAL: When certain variables, constants, procedures or labels are to be used in only one program module, they are declared local using LOCAL directive 20. MACRO: A sequence of instructions to which a name is assigned. Same as subroutines. 21. NAME: A large program module contain several program modules so specific name can be given to each program module using NAME directive. 22. OFFSET: It is an operator to determine the offset of a variable or procedure with respect to the base of the segment which contains the named variable or procedure. .M.M. Arun Prasath., AP/ECE 17
  18. 18. Assembler Directives of 8086 23. ORG (Originate): The ORG directive directs the assembler to set the location counter at memory address specified after the directive. 24. PROC (Procedure): It indicate the start of a procedure. The type of the procedure FAR or NEAR is to be specified after the directive. NEAR is used to call a procedure which is within the program module and FAR is used to call from some other program module. 25. PTR (Pointer): It indicates the type (BYTE, WORD or DW) of a variable or label. 26. PUBLIC: a large program usually consist of several program modules. The variables, constants, procedures and labels defined in a program module may be used in some other program module. So such items are to be declared public using PUBLIC directive. 27. RECORD: It defines the bit pattern within a byte or word 28. SEG(Segment): It is an operator used before a variable, procedures and label .M.M. Arun Prasath., AP/ECE 18
  19. 19. Assembler Directives of 8086 29. SEGMENT (Logical Segment): It indicates the beginning of a logical segment. The SEGMENT and ENDS directives are used to enclose a logical segment containing code or data. 30. SHORT: It is an operator. It informs assembler that only one byte for the displacement is required to code a jump instruction. 31. SIZE: it is an operator to determine the number of bytes allocated to a data item. It differs from the LENGTH operator as it determines the no. of elements in a data item. 32. STRUCK or STRUC (Structure Declaration): It defines the beginning of a data structure which is a collection of primary data types such as DB, DW, DD is declared. 33. TYPE: It is an operator that determines the type of a variable. It actually determines the no. of bytes allocated to the variable and substitutes the no. in place of the variable before which TYPE appears. .M.M. Arun Prasath., AP/ECE 19
  21. 21. 1.DATA TRANSFER INSTRUCTIONS GENERAL PURPOSE BYTE OR WORD TRANSFER INSTRUCTIONS  MOV Instruction - MOV destination, source Example: MOV DL,[BX] : Copy byte from memory at BX to DL  PUSH Instruction - PUSH source Example: PUSH BX  POP Instruction - POP destination Example: POP DX  XCHG Instruction - Exchange XCHG destination, source Example: XCHG AX, DX  XLAT/XLATB Instruction - Translate a byte in AL with byte pointed in BX Example: MOV AL, [BX+AL] .M.M. Arun Prasath., AP/ECE 21
  22. 22. 1.DATA TRANSFER INSTRUCTIONS SIMPLE INPUT AND OUTPUT PORT TRANSFER INSTRUCTION  IN Instruction - Copy data from a port IN accumulator, port Example: IN AL,0C8H  OUT Instruction - Output a byte or word to a port – OUT port, accumulator AL or AX. Example: OUT 3BH, AL SPECIAL ADDRESS TRANSFER INSTRUCTIONS  LEA Instruction - Load Effective Address Syntax – LEA register, source Example: LEA BX, PRICE ;Load BX with offset of PRICE in DS  LDS Instruction - Load register and DS with words from memory Syntax – LDS register, memory address of first word Example: LDS BX, [4326] ; copy the contents of the memory at 4326H in DS to BL, contents of the 4327H to BH.  LES Instruction - Load register and ES with words from memory .M.M. Arun Prasath., AP/ECE Syntax – LES register, memory address of first word 22
  23. 23. 1.DATA TRANSFER INSTRUCTIONS FLAG TRANSFER INSTRUCTION  LAHF Instruction - Load Register AH From Flags copies the value of SF, ZF, AF, PF, and CF, into bits of 7, 6, 4, 2, 0 respectively of AH register.  SAHF instruction - Store AH Register into FLAGS SAHF instruction transfers the bits 0-7 of AH of SF, ZF, AF, PF, and CF, into the Flag register.  PUSHF Instruction - Push flag register on the stack This instruction decrements the SP by 2 and copies the word in flag register  POPF Instruction - Pop word from top of stack to flag – register. to the memory location pointed by SP. .M.M. Arun Prasath., AP/ECE 23
  24. 24. 2.ARITHMETIC INSTRUCTIONS ADDITION INSTRUCTIONS  ADD Instruction - ADD destination, source Example: ADD DX, BX  ADC Instruction - Add with carry Example: ADC CL,BL  INC Instruction - Increment - INC destination Example: INC BL  AAA Instruction - ASCII Adjust after Addition We can add two ASCII numbers directly and use AAA after addition so as to get result directly in BCD. (Works with AL only)  DAA Instruction - Decimal Adjust Accumulator .M.M. Arun Prasath., AP/ECE 24
  25. 25. 2.ARITHMETIC INSTRUCTIONS SUBTRACTION INSTRUCTION  SUB Instruction - Subtract two numbers Example: SUB CX, BX  SBB Instruction - Subtract with borrow SBB destination, source Example: SBB CX, BX  DEC Instruction - Decrement destination register or memory.  NEG Instruction - Form 2’s complement – Syntax: NEG destination  CMP Instruction - Compare byte or word and sets the flag Syntax: CMP destination, source.  AAS Instruction - ASCII Adjust for Subtraction  DAS Instruction - Decimal Adjust after Subtraction .M.M. Arun Prasath., AP/ECE 25
  26. 26. 2.ARITHMETIC INSTRUCTIONS MULTIPLICATION INSTRUCTION  MUL Instruction - Multiply unsigned bytes or words Syntax: MUL source Example: MUL BL Syntax: IMUL source Example: IMUL BH  IMUL Instruction - Multiply signed number  AAM Instruction - ASCII adjust after Multiplication DIVISION INSTRUCTION  DIV Instruction - Unsigned divide Syntax: DIV source Example: DIV BH ; AX / BH ; AX =Quotient & AH =Remainder.  IDIV Instruction - Divide by signed byte or word Example: IDIV BL ; Syntax: IDIV source Signed word in AX is divided by signed byte in BL  AAD Instruction - ASCII adjust before Division  CBW Instruction - Convert signed Byte to signed word  CWD Instruction - Convert Signed Word to Signed Double word .M.M. Arun Prasath., AP/ECE 26 ( CBW and CWD works only with AL,AX and DX registers.)
  27. 27. 3.LOGICAL INSTRUCTIONS LOGICAL INSTRUCTION  NOT Instruction - Invert each bit of operand Ex: NOT BX ; Complement contents of BX register.  AND Instruction - AND corresponding bits of two operands Ex: AND BH, CL ; AND byte in CL with byte in BH ;result in BH Ex: OR AH, CL ; CL is OR’ed with AH, result in AH.  OR Instruction - Logically OR corresponding of two operands  XOR Instruction - Exclusive XOR destination, source  TEST Instruction – AND operand to update flags Ex: XOR BX, CX Ex: TEST AL, BH ; Exclusive OR CX with BX and Result BX ; AND BH with AL. no result is stored . Update PF, SF, ZF .M.M. Arun Prasath., AP/ECE 27
  28. 28. 3.LOGICAL INSTRUCTIONS SHIFT INSTRUCTION  SAL/SHL Instruction - Shift operand bits left, put zero in LSB(s) Ex: ; CF = 0, BX = 11100101 11010011 SAL BX, 1 ; Shift BX contents by 1 bit position towards left ; CF = 1, BX = 11001011 10100110  SHR Instruction - Shift operand bits right, put zero in MSB Ex: ; SI = 10010011 10101101 , CF = 0 SHR SI, 1 ; Result: SI = 01001001 11010110 and CF = 1  SAR Instruction - Shift operand bits right, new MSB = old MSB Ex: ; AL = 00011101 = +29 decimal, CF = 0 SAR AL, 1 ; Shift signed byte in AL towards right ; AL = 00001110 = +14 decimal, CF = 1 .M.M. Arun Prasath., AP/ECE 28
  29. 29. 3.LOGICAL INSTRUCTIONS ROTATE INSTRUCTION  ROL Instruction - Rotate all bits of operand left, MSB to LSB Ex: ;CF =0, BX = 10111011 01110101 ROL BX, 1 ;Result: CF =1, BX = 01110110 11101011  ROR Instruction - Rotate all bits of operand right, LSB to MSB Ex: ;CF =0, BX = 00111011 01110101 ROR BX, 1 ;Result: CF =1, BX = 10011101 10111010  RCL Instruction - Rotate operand around to the left through CF Ex: ;CF=0, BH = 10110011 RCL BH, 1 ;Result : BH =01100110, CF = 1  RCR Instruction - Rotate operand around to the right through CF Ex: ;CF = 1, BL = 00111000 RCR BL, 1 ;Result: BL = 10011100, CF =0 .M.M. Arun Prasath., AP/ECE 29
  30. 30. 4.CONTROL INSTRUCTIONS  CALL – call a procedure UNCONDITIONAL TRANSFER INSTRUCTIONS  RET – return execution from procedure  JMP – unconditional jump to specified destination .M.M. Arun Prasath., AP/ECE 30
  31. 31. 4.CONTROL INSTRUCTIONS CONDITIONAL TRANSFER INSTRUCTIONS  JA/JNBE - Jump if above/Jump if not below or not equal  JAE/JNB - jump if above or equal/Jump if not below  JB/JNAE - jump if below/jump if not above or not equal  JBE/JNA - jump if below or equal/jump if not above  JC – jump if carry  JE/JZ – jump if equal/jump if zero  JG/JNLE – jump if greater/jump if not less or not equal  JGE/JNL - jump if greater or equal/jump if not less than  JL/JNGE- jump if less/jump if not greater or not equal Cont… .M.M. Arun Prasath., AP/ECE 31
  32. 32. Cont… 4.CONTROL INSTRUCTIONS CONDITIONAL TRANSFER INSTRUCTIONS JLE/JNG - jump if less or equal/jump if not greater  JNC – jump if no carry  JNE/JNZ - jump if not equal/jump if not zero  JNO – jump if no overflow  JNP/JPO - jump if no parity/jump if parity odd  JNS – jump if no signed  JO- jump if overflow  JP/JPE - jump if parity/jump if parity even  JS- jump if sign .M.M. Arun Prasath., AP/ECE 32
  33. 33. 4.CONTROL INSTRUCTIONS ITERATION CONTROL INSTRUCTIONS  LOOP – decresae CX, jump to label if CX not equal to 0. Count is loaded  LOOPE/LOOPZ – decresae CX, jump to label if CX equal/decresae CX, in CX register jump to label if CX not zero.  LOOPNE/LOOPNZ - decresae CX, jump to label if CX not  JCXZ – jump if CX is zero. equal/decresae CX, jump to label if CX not zero. .M.M. Arun Prasath., AP/ECE 33
  34. 34. 5.PROCESSOR CONTROL INSTRUCTIONS  These instructions are used to change the process of the Microprocessor. FLAG SET/CLEAR EXTERNAL HARDWARE INSTRUCTIONS SYNCHRONIZATION INSTRUCTIONS  CLC - clear carry flag  WAIT - idle condition  STC - set carry flag  HLT - halt the system  CMC - complement carry flag  ESC - When 8086 fetches an ESC instruction,  STD - set direction flag  CLD - clear direction flag  STI - set interrupt enable flag the coprocessor decodes the instruction and carries out the action specified by the 6 bit code. In case of 8086 it treats ESC instruction as  CLI- clear interrupt enable an NOP. The coprocessor treats all of the 8086 flag  LOCK - bus lock signal instruction as an NOP except ESC.  NOP - no operation Arun Prasath., AP/ECE .M.M. 34
  35. 35. 6.STRING CONTROL INSTRUCTIONS • The string instructions function easily on blocks of memory. help for easy program writing and execution. They can speed up the manipulating code.  REP/REPE/REPZ/REPNE/REPNZ - Repeat String instruction until specified condition exist  MOVS/MOVSB/MOVSW - Move string byte or string word  COMPS/COMPSB/COMPSW – compare string Syntax: MOVS destination, source  SCAS/SCASB/SCASW – Scan string byte or a string word.  LODS/LODSB/LODSW - This instruction copies a byte from a string location pointed to by SI to AL or a word from a string location pointed to by SI to AX. If DF is cleared to 0, SI will automatically incremented to point to the next element of string.  STOS/STOSB/STOSW- Store byte or word in string. .M.M. Arun Prasath., AP/ECE 35
  36. 36. 7.INTERRUPT CONTROL INSTRUCTIONS  INT Interrupt type  INTO Interrupt on overflow  IRET Interrupt return .M.M. Arun Prasath., AP/ECE 36