80x86 Instructions by iij26547

VIEWS: 0 PAGES: 44

									       80x86 Instructions



            Filename: csf-instructions-0809.ppt




2010-6-18               EIE311-CSF-instructions   1
Objectives
Upon completion of this chapter, you will be able to

    Explain the instruction cycle
    Describe the effect of MOV and ADD instructions on their operands
    State the purpose of the code segment, data segment, stack
     segment, and extra segment
    Explain the difference between a logical address and a physical
     address
    Explain the function of PUSH and POP instructions
    List the bits of the flag register and brief state the purpose of each
     bit
    List the addressing modes of the 80x86 and recognize examples of
     each mode




2010-6-18                       EIE311-CSF-instructions                       2
Instruction Cycle
 1.         Fetch the instruction from memory into the
            instruction register.
 2.         Decode the instruction.
 3.         Locate the operands used by the instruction.
 4.         Fetch operands from memory (if necessary).
 5.         Execute the operation in processor register.
 6.         Store the results in the proper place.
 7.         Go back to step 1 to fetch the next instruction.


2010-6-18                   EIE311-CSF-instructions        3
             operand                                 operand addr.
                                                        4
                                                                        Memory
operand           5
             6
                                                                                        DS
                                                         1                Data          or
                                                                                        ES
                                                     inst. addr.        segment



                       2                                                 Program
                                                              instruction segment   CS:[IP]

                       3             e.g.: Add AX,[100H]
 2010-6-18                 EIE311-CSF-instructions                                  4
    Intel Instruction Set




2010-6-18        EIE311-CSF-instructions   5
Instruction Basics

    An instruction in computer contains
           Opcode and
           Operand(s) (optional)
    Opcode specifies the operation to be
     performed
    Operand specifies the data to be processed




2010-6-18                   EIE311-CSF-instructions   6
Instruction Format




2010-6-18     EIE311-CSF-instructions   7
    Luckily we do not often need to code into
     binary (or hexadecimal) form, that is why we
     have an assembler. The examples shows
     how the instructions are coded and why
     different instructions contain different
     numbers of bytes. This knowledge may help
     when generating efficient code.




2010-6-18             EIE311-CSF-instructions       8
Types of Instructions

    Data Movement Instructions
    Program Control Instructions
    Arithmetic and Logic Instructions
    etc.




2010-6-18              EIE311-CSF-instructions   9
       Data Movement
       Instructions




2010-6-18     EIE311-CSF-instructions   10
MOV Instruction

MOV is the main data transfer instruction.

MOV         destination, source        ;copy source operand to destination

Examples:

MOV         DL, 55H         ;move 55H into register DL
MOV         AH, DL          ;copy the contents of DL into AH (now AH=DL=55H)

MOV         CX, 468FH       ;move 468FH into CX (now CH=46H, CL=8FH)
MOV         DS, CX          ;now DS=CX=468FH




2010-6-18                         EIE311-CSF-instructions                    11
MOV Instruction (cont.)




2010-6-18     EIE311-CSF-instructions   12
PUSH and POP

    There are many variations of data movement
     instructions that perform special movement
     tasks such as PUSH and POP.




2010-6-18            EIE311-CSF-instructions   13
PUSH and POP (cont.)

    PUSH and POP transfer data to and from the stack.
     The stack is an area of memory that is reused and
     grows in size with each PUSH and shrinks in size
     with each POP.
    PUSH and POP function with either 16- or 32-bit
     data.
    PUSHF (PUSHFD) and POPF (POPFD) save and
     restore the flags (EFLAGS).
    PUSHA (PUSHAD) and POPA (POPAD) save and
     restore all the registers.


2010-6-18              EIE311-CSF-instructions           14
IN and OUT Instructions

    The two I/O instructions transfer data
     between an I/O device and the accumulator
     (AL, AX, and EAX).
    16-bit I/O address means there are up to 64K
     I/O devices possible in a system.




2010-6-18            EIE311-CSF-instructions    15
Examples of IN and OUT Instructions

    IN AL, port1 ; 8-bit port number
    IN AX, port2
    IN EAX, port3
    IN AX, DX     ; 16-bit port number stored in DX
    OUT port4, AX
    OUT DX, AX




2010-6-18              EIE311-CSF-instructions         16
Segments in the 80x86

    A segment is an area of memory that
     includes up to 64K bytes.
    Three categories of segments: the code
     segment (CS), data segment (DS or ES), and
     stack segment (SS)




2010-6-18            EIE311-CSF-instructions   17
 Intel 8086’s Addressing Scheme




2010-6-18      EIE311-CSF-instructions   18
Various Addresses

    Logical address: a segment value and an offset address
    Physical address =     segment address x 16 +
                            offset address
     Example:




2010-6-18                EIE311-CSF-instructions              19
Code Segment




2010-6-18      EIE311-CSF-instructions   20
Logical Address vs. Physical Address in
the Code Segment




2010-6-18       EIE311-CSF-instructions   21
Logical Address vs. Physical Address in
the Code Segment (cont.)




2010-6-18       EIE311-CSF-instructions   22
Addressing Modes

    Operands are required for most operations (e.g.
     ADD).
    Addressing mode tells how we can determine the
     exact location (physical address in the real mode or
     linear address in the protected mode) of the data
     (operand) we want to manipulate.
    The more powerful a CPU, the more modes it
     supports.




2010-6-18                EIE311-CSF-instructions            23
80x86 Addressing Modes

    Immediate Mode
    Register Mode
    Direct Addressing Mode
    Register-Indirect Mode
    Based Relative Mode
    Indexed Relative Mode
    Based Indexed Relative Mode


2010-6-18           EIE311-CSF-instructions   24
Immediate Mode




2010-6-18   EIE311-CSF-instructions   25
Immediate Mode (cont.)




2010-6-18    EIE311-CSF-instructions   26
Register Mode




2010-6-18       EIE311-CSF-instructions   27
Direct Addressing Mode
                                       The little endian method
                                       used in the Intel family

                                       The little endian method:
                                       the high byte goes to the
                                       high address and the low
                                       byte goes to the low
                                       address

                                       The big endian method:
                                       the high byte goes to the
                                       low address and the low
                                       byte goes to the high
                                       address




2010-6-18    EIE311-CSF-instructions                         28
Direct Addressing Mode (cont.)




2010-6-18     EIE311-CSF-instructions   29
Register Indirect




2010-6-18      EIE311-CSF-instructions   30
Register Indirect (cont.)




2010-6-18      EIE311-CSF-instructions   31
Based Relative Mode




                                       based




2010-6-18    EIE311-CSF-instructions           32
Based Indexed Relative Mode




                                       Based indexed relative mode
                    Base relative-plus-index


2010-6-18    EIE311-CSF-instructions                                 33
Based Indexed Relative Mode (cont.)




            Note: a different format used here.




2010-6-18                  EIE311-CSF-instructions   34
Offset Registers and Segment Override




2010-6-18       EIE311-CSF-instructions   35
Summary of 80x86 Addressing Modes




2010-6-18     EIE311-CSF-instructions   36
Stack Segment

    The stack segment
           holds data temporarily and
           stores return addresses for procedures
            (subroutines).
    The stack segment is maintained by the stack
     pointer (SP) and the stack segment register
     (SS) in Intel’s 8086.
    The stack segment is an LIFO (last-in first-
     out) memory, which describes the way that
     data are stored and removed from the stack.

2010-6-18                   EIE311-CSF-instructions   37
   Stack Operations



Lower memory
address


Higher memory
address




   2010-6-18     EIE311-CSF-instructions   38
Stack Operations (cont.)




2010-6-18     EIE311-CSF-instructions   39
Stack Operations (cont.)




2010-6-18     EIE311-CSF-instructions   40
Nonoverlapping vs. Overlapping
Segments




2010-6-18      EIE311-CSF-instructions   41
Flag Register

Also referred to as the program status register. It consists of
   conditional flags and control flags.




2010-6-18                  EIE311-CSF-instructions                42
Flag Register and ADD Instruction




2010-6-18     EIE311-CSF-instructions   43
Use of the Zero Flag for Looping




2010-6-18     EIE311-CSF-instructions   44

								
To top