kichapt_01

Upload: omar-shahid

Post on 09-Apr-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/8/2019 KIchapt_01

    1/49

    Assembly Language for IntelAssembly Language for Intel--BasedBased

    Computers, 4Computers, 4thth EditionEdition

    Chapter 1: Basic Concepts

    (c) Pearson Education, 2002. All rights reserved. You may modify and copy this slide show for your personal use, or for

    use in the classroom, as long as this copyright statement, the author's name, and the title are not changed.

    Chapter corrections (Web) Assembly language sources (Web)

    Printing a slide show

    Slides prepared by Kip R. Irvine

    Revision date: 09/15/2002

    Kip R. Irvine

  • 8/8/2019 KIchapt_01

    2/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 2

    Chapter OverviewChapter Overview

    Welcome to Assembly Language

    Virtual Machine Concept

    Data Representation

    Boolean Operations

  • 8/8/2019 KIchapt_01

    3/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 3

    Welcome to Assembly LanguageWelcome to Assembly Language

    Some Good Questions to Ask

    Assembly Language Applications

  • 8/8/2019 KIchapt_01

    4/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 4

    Some Good Questions to AskSome Good Questions to Ask

    Why am I taking this course (reading this book)?

    What background should I have?

    What is an assembler?

    What hardware/software do I need? What types of programs will I create?

    What do I get with this book?

    What will I learn?

  • 8/8/2019 KIchapt_01

    5/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 5

    Welcome to Assembly LanguageWelcome to Assembly Language (cont)(cont)

    How does assembly language (AL) relate to machine

    language?

    How do C++ and Java relate to AL?

    Is AL portable? Why learn AL?

  • 8/8/2019 KIchapt_01

    6/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 6

    Assembly Language ApplicationsAssembly Language Applications

    Some representative types of applications:

    Business application for single platform

    Hardware device driver

    Business application for multiple platforms Embedded systems & computer games

    (see next panel)

  • 8/8/2019 KIchapt_01

    7/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 7

    Comparing ASM to HighComparing ASM to High--Level LanguagesLevel Languages

  • 8/8/2019 KIchapt_01

    8/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 8

    Virtual Machine ConceptVirtual Machine Concept

    Virtual Machines

    Specific Machine Levels

  • 8/8/2019 KIchapt_01

    9/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 9

    Virtual MachinesVirtual Machines

    Tanenbaum: Virtual machine concept

    Programming Language analogy:

    Each computer has a native machine language (language

    L0) that runs directly on its hardware

    A more human-friendly language is usually constructed

    above machine language, called Language L1

    Programs written in L1 can run two different ways:

    Interpretation L0 program interprets and executes L1

    instructions one by one

    Translation L1 program is completely translated into an L0program, which then runs on the computer hardware

  • 8/8/2019 KIchapt_01

    10/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 10

    Translating LanguagesTranslating Languages

    English: Display the sum of A times B plus C.

    C++: cout

  • 8/8/2019 KIchapt_01

    11/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 11

    Specific Machine LevelsSpecific Machine Levels

    High -Lev e l Language

    A s s e m b ly L a n g u a g e

    O p e r a tin g S y s t e m

    Ins t ruc t ion Se t

    Arch i tec tu re

    Mic roarch i tec tu re

    D ig ita l Log ic Lev e l 0

    Lev e l 1

    Lev e l 2

    Lev e l 3

    Lev e l 4

    Lev e l 5

    (descriptions of individual levels

    follow . . . )

  • 8/8/2019 KIchapt_01

    12/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 12

    HighHigh--Level LanguageLevel Language

    Level 5

    Application-oriented languages

    C++, Java, Pascal, Visual Basic . . .

    Programs compile into assembly language(Level 4)

  • 8/8/2019 KIchapt_01

    13/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 13

    Assembly LanguageAssembly Language

    Level 4

    Instruction mnemonics that have a one-to-one correspondence to machine language

    Calls functions written at the operating

    system level (Level 3)

    Programs are translated into machinelanguage (Level 2)

  • 8/8/2019 KIchapt_01

    14/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 14

    Operating SystemOperating System

    Level 3

    Provides services to Level 4 programs

    Translated and run at the instruction set

    architecture level (Level 2)

  • 8/8/2019 KIchapt_01

    15/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 15

    Instruction Set ArchitectureInstruction Set Architecture

    Level 2

    Also known as conventional machine

    language

    Executed by Level 1 (microarchitecture)program

  • 8/8/2019 KIchapt_01

    16/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 16

    MicroarchitectureMicroarchitecture

    Level 1

    Interprets conventional machine

    instructions (Level 2)

    Executed by digital hardware (Level 0)

  • 8/8/2019 KIchapt_01

    17/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 17

    Digital LogicDigital Logic

    Level 0

    CPU, constructed from digital logic gates

    System bus

    Memory Implemented using bipolar transistors

    next: Data Representation

  • 8/8/2019 KIchapt_01

    18/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 18

    Data RepresentationData Representation

    Binary Numbers Translating between binary and decimal

    Binary Addition

    Integer Storage Sizes

    Hexadecimal Integers Translating between decimal and hexadecimal

    Hexadecimal subtraction

    Signed Integers

    Binary subtraction Character Storage

  • 8/8/2019 KIchapt_01

    19/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 19

    Binary NumbersBinary Numbers

    Digits are 1 and 0

    1 = true

    0 = false

    MSB most significant bit LSB least significant bit

    Bit numbering:015

    1 0 1 1 0 0 1 0 1 0 0 1 1 1 0 0

    B L B

  • 8/8/2019 KIchapt_01

    20/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 20

    Binary NumbersBinary Numbers

    Each digit (bit) is either 1 or 0

    Each bit represents a power of 2:

    1 1 1 1 1 1 1 1

    27 26 25 24 23 22 21 20

    Every binary

    number is a

    sum of powers

    of 2

  • 8/8/2019 KIchapt_01

    21/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 21

    Translating Binary to DecimalTranslating Binary to Decimal

    Weighted positional notation shows how to calculate the

    decimal value of each binary bit:

    dec = (Dn-1v 2n-1) (D

    n-2v 2n-2) ... (D

    1v 21) (D

    0v 20)

    D = binary digit

    binary 00001001 = decimal 9:

    (1 v 23) + (1 v 20) = 9

  • 8/8/2019 KIchapt_01

    22/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 22

    Translating Unsigned Decimal to BinaryTranslating Unsigned Decimal to Binary

    Repeatedly divide the decimal integer by 2. Eachremainder is a binary digit in the translated value:

    37 = 100101

  • 8/8/2019 KIchapt_01

    23/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 23

    Binary AdditionBinary Addition

    Starting with the LSB, add each pair of digits, includethe carry if present.

    0 0 0 0 0 1 1 1

    0 0 0 0 0 1 0 0

    +

    0 0 0 0 1 0 1 1

    1

    (4)

    (7)

    (11)

    carry:

    01234b it pos ition: 5 67

  • 8/8/2019 KIchapt_01

    24/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 24

    Integer Storage SizesInteger Storage Sizes

    byte

    1 6

    8

    32

    word

    doub leword

    64quadword

    What is the largest unsigned integer that may be stored in 20 bits?

    Standard sizes:

  • 8/8/2019 KIchapt_01

    25/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 25

    Hexadecimal IntegersHexadecimal Integers

    Binary values are represented in hexadecimal.

  • 8/8/2019 KIchapt_01

    26/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 26

    Translating Binary to HexadecimalTranslating Binary to Hexadecimal

    Each hexadecimal digit corresponds to 4 binary bits.

    Example: Translate the binary integer

    000101101010011110010100 to hexadecimal:

  • 8/8/2019 KIchapt_01

    27/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 27

    Converting Hexadecimal to DecimalConverting Hexadecimal to Decimal

    Multiply each digit by its corresponding power of 16:

    dec = (D3 v 163) + (D2 v 16

    2) + (D1 v 161) + (D0 v 16

    0)

    Hex 1234 equals (1 v 163) + (2 v 162) + (3 v 161) + (4 v 160), or

    decimal 4,660.

    Hex 3BA4 equals (3 v 163) + (11 * 162) + (10 v 161) + (4 v 160), or

    decimal 15,268.

  • 8/8/2019 KIchapt_01

    28/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 28

    Powers of 16Powers of 16

    Used when calculating hexadecimal values up to 8 digits

    long:

  • 8/8/2019 KIchapt_01

    29/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 29

    Converting Decimal to HexadecimalConverting Decimal to Hexadecimal

    decimal 422 = 1A6 hexadecimal

  • 8/8/2019 KIchapt_01

    30/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 30

    Hexadecimal AdditionHexadecimal Addition

    Divide the sum of two digits by the number base (16). The quotientbecomes the carry value, and the remainder is the sum digit.

    36 28 28 6A

    42 45 58 4B78 6D 80 B5

    11

    21 / 16 = 1, rem 5

    Important skill: Programmers frequently add and subtract the

    addresses of variables and instructions.

  • 8/8/2019 KIchapt_01

    31/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 31

    Hexadecimal SubtractionHexadecimal Subtraction

    When a borrow is required from the digit to the left, add10h to the current digit's value:

    C6 75A2 4724 2E

    1

    10h + 5 = 15h

    Practice: The address ofvar1 is 00400020. The address of the next

    variable after var1 is 0040006A. How many bytes are used by var1?

  • 8/8/2019 KIchapt_01

    32/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 32

    Signed IntegersSigned Integers

    The highest bit indicates the sign. 1 = negative,0 = positive

    1 1 1 1 0 1 1 0

    0 0 0 0 1 0 1 0

    sign bit

    Negat ive

    Posi t ive

    If the highest digit of a hexadecimal integer is > 7, the value is

    negative. Examples: 8A, C5, A2, 9D

  • 8/8/2019 KIchapt_01

    33/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 33

    Forming the Two's ComplementForming the Two's Complement

    Negative numbers are stored in two's complementnotation

    Represents the additive Inverse

    Note that 00000001 + 11111111 = 00000000

  • 8/8/2019 KIchapt_01

    34/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 34

    Binary SubtractionBinary Subtraction

    When subtracting A B, convert B to its two'scomplement

    Add A to (B)

    0 0 0 0 1 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 1

    0 0 0 0 1 0 0 1

    Practice: Subtract 0101 from 1001.

  • 8/8/2019 KIchapt_01

    35/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 35

    Learn How To Do the Following:Learn How To Do the Following:

    Form the two's complement of a hexadecimal integer

    Convert signed binary to decimal

    Convert signed decimal to binary

    Convert signed decimal to hexadecimal Convert signed hexadecimal to decimal

  • 8/8/2019 KIchapt_01

    36/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 36

    Ranges of Signed IntegersRanges of Signed Integers

    The highest bit is reserved for the sign. This limits the range:

    Practice: What is the largest positive value that may be stored in 20 bits?

  • 8/8/2019 KIchapt_01

    37/49

  • 8/8/2019 KIchapt_01

    38/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 38

    Numeric Data RepresentationNumeric Data Representation

    pure binary

    can be calculated directly

    ASCII binary

    string of digits: "01010101"

    ASCII decimal

    string of digits: "65"

    ASCII hexadecimal

    string of digits: "9C"

    next: Boolean Operations

  • 8/8/2019 KIchapt_01

    39/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 39

    Boolean OperationsBoolean Operations

    NOT

    AND

    OR

    Operator Precedence Truth Tables

  • 8/8/2019 KIchapt_01

    40/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 40

    Boolean AlgebraBoolean Algebra

    Based on symbolic logic, designed by George Boole Boolean expressions created from:

    NOT, AND, OR

  • 8/8/2019 KIchapt_01

    41/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 41

    NOTNOT

    Inverts (reverses) a boolean value

    Truth table for Boolean NOT operator:

    NOT

    Digital gate diagram for NOT:

  • 8/8/2019 KIchapt_01

    42/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 42

    ANDAND

    Truth table for Boolean AND operator:

    AND

    Digital gate diagram for AND:

  • 8/8/2019 KIchapt_01

    43/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 43

    OROR

    Truth table for Boolean OR operator:

    OR

    Digital gate diagram for OR:

  • 8/8/2019 KIchapt_01

    44/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 44

    Operator PrecedenceOperator Precedence

    Examples showing the order of operations:

  • 8/8/2019 KIchapt_01

    45/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 45

    Truth TablesTruth Tables (1 of 3)(1 of 3)

    A Boolean function has one or more Boolean inputs,and returns a single Boolean output.

    A truth table shows all the inputs and outputs of a

    Boolean function

    Example: X Y

  • 8/8/2019 KIchapt_01

    46/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 46

    Truth TablesTruth Tables (2 of 3)(2 of 3)

    Example:X

    Y

  • 8/8/2019 KIchapt_01

    47/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 47

    Truth TablesTruth Tables (3 of 3)(3 of 3)

    Example: (Y

    S)

    (X

    S)

    muxX

    Y

    Z

    Two-input multiplexer

  • 8/8/2019 KIchapt_01

    48/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 48

    54 68 65 20 45 6E 6454 68 65 20 45 6E 64

    What do these numbers represent?

  • 8/8/2019 KIchapt_01

    49/49

    Web site ExamplesIrvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 49

    Printing this Slide ShowPrinting this Slide Show

    To print this slide show with black characters on awhite background, do the following:

    Select Print... from the File menu.

    Select Handouts in the Print what drop-down box. Select 2 or 3 in the Slides per page drop-down box.

    Select the Pure black and white check box (optional)

    Click on OK to begin printing.

    Back to the title page