8051-CH2 Intro Assemblys2'10

download 8051-CH2 Intro Assemblys2'10

of 22

Transcript of 8051-CH2 Intro Assemblys2'10

  • 8/9/2019 8051-CH2 Intro Assemblys2'10

    1/22

  • 8/9/2019 8051-CH2 Intro Assemblys2'10

    2/22

    8051 Assembly Language8051 Assembly LanguageProgrammingProgramming

  • 8/9/2019 8051-CH2 Intro Assemblys2'10

    3/22

    8051 Assembly LanguageProgramming

    OutlinesOutlines 8051 programming model

    Assembly language syntax

    Operation codes and operands

    How 8051 interprets binary data

    Machine instructions Example of Assembly language program

    8051 Instruction Set

  • 8/9/2019 8051-CH2 Intro Assemblys2'10

    4/22

    Programming Model

    A programmer should; Know the internal structure of the 8051

    Understand the Programming modeli.e. how programmers see the 8051

    Know how to access the registers and

    accumulators with programs

  • 8/9/2019 8051-CH2 Intro Assemblys2'10

    5/22

    Binary Data

    Unlike human, computers do not know verbalinstructions; they only know 0s and 1s.

    Binary data: program in a stream of 0s and 1s

    It is also called Machine Language

    For convenient purpose, machine languageprograms are usually expressed in hexadecimal(i.e. base-16) format

  • 8/9/2019 8051-CH2 Intro Assemblys2'10

    6/22

    8051 Programming Model

  • 8/9/2019 8051-CH2 Intro Assemblys2'10

    7/22

    8051 Registers8051 Registers

  • 8/9/2019 8051-CH2 Intro Assemblys2'10

    8/22

    8051 Registers8051 Registers

  • 8/9/2019 8051-CH2 Intro Assemblys2'10

    9/22

    8051 Program Counter & ROM Space8051 Program Counter & ROM Space

  • 8/9/2019 8051-CH2 Intro Assemblys2'10

    10/22

    Assembly Language Syntax Syntax = format/rule

    [label:] mnemonic [operands] [;comment] Items in square brackets are optional

    Example:

    Thus, Machine Code = Operation Code (Opcode) + Operand

  • 8/9/2019 8051-CH2 Intro Assemblys2'10

    11/22

    Mnemonic/ Operation Code

    (Opcode)

    Program = a set of instructionsAll computers work according to the

    program

    All instructions contain a verb , whichtells the computer what to do

    This verb is called mnemonic/operationcode e.g. MOV R0, #12h MOV is theopcode

  • 8/9/2019 8051-CH2 Intro Assemblys2'10

    12/22

    Operand Apart from Opcode, an instruction also includes

    object to act on. The object is called an operand.

    Operand is optional. Instructions can have one,

    two or no operands.

    e.g.

    MOV R0, #12h --- R0 and #12h are two operands ADD R1 --- R1 is the only one operand

    NOP --- no operand follows

  • 8/9/2019 8051-CH2 Intro Assemblys2'10

    13/22

    Pseudo-Instructions/DirectivesAssembler state controlAssembler state control

    ORG (origin)

    indicates the beginning of the instructions. The numberthat either hex or decimal.

    END Indicates the end of assembly instructions.

    EQU (equate)

    used to define a constant without occupying a memorylocation. It does not set aside storage for a data itembut associates a constant value with a data label so thatwhen the label appears in the program. Its constant

    value will be substituted for the label. Eg. COUNT EQU 25H

  • 8/9/2019 8051-CH2 Intro Assemblys2'10

    14/22

    Define Byte (DB) and Data TypesDefine Byte (DB) and Data Types

    Used to define 8-bit data and store them inassigned memory locations. Define data can be indecimal, binary, hex, or ASCII formats.

    ORG 500HORG 500H

    DATA1: DB 28DATA1: DB 28 ;DECIMAL (1C in Hex);DECIMAL (1C in Hex)

    DATA2: DB 00110101BDATA2: DB 00110101B ;BINARY (35 in Hex);BINARY (35 in Hex)DATA3: DB 39H ;DATA3: DB 39H ;HEXHEX

    ORG 510HORG 510H

    DATA4: DBDATA4: DB 25912591 ; ASCII NUMBERS; ASCII NUMBERSORG 518HORG 518H

    DATA6: DBDATA6: DB My name isMy name is DeenDeen ;ASCII CHARACTERS;ASCII CHARACTERS

  • 8/9/2019 8051-CH2 Intro Assemblys2'10

    15/22

    Opcodes Assembly languageAddress/Program Pointer

  • 8/9/2019 8051-CH2 Intro Assemblys2'10

    16/22

    Programming is both a scienceProgramming is both a science

    and art !!and art !!

    ScienceScience rules of grammar,rules of grammar,punctuation, spelling &punctuation, spelling &

    structure.structure.

    ArtArt how the words arehow the words arearrangedarranged

  • 8/9/2019 8051-CH2 Intro Assemblys2'10

    17/22

    How to tell a lump of sand what to do:How to tell a lump of sand what to do:

    1. study common programming techniques

    2. analyze example programs

    3. write many practice programs

    [ Read chapter 4 from Ayala for revision on basic assembly languagRead chapter 4 from Ayala for revision on basic assembly language concepts.e concepts.]

  • 8/9/2019 8051-CH2 Intro Assemblys2'10

    18/22

    Program Development

    Stop

    Create /edit

    source codes

    Assemble

    source codes

    Syntax

    Errors?

    Test / debug

    program

    Logical

    Errors?

    Start

    Yes

    Yes

    No

    No

    Text editor

    Debugger

    Assembler

  • 8/9/2019 8051-CH2 Intro Assemblys2'10

    19/22

    Steps to Create a ProgramSteps to Create a Program

  • 8/9/2019 8051-CH2 Intro Assemblys2'10

    20/22

    Assembler/LinkerAssembler/Linker

    AssemblerAssembler

    Change mnemonic code into machine codeChange mnemonic code into machine code

    Label can be used to represent symbolicLabel can be used to represent symbolic

    address/dataaddress/data

    Directives : like preDirectives : like pre--processing operator (#) in Cprocessing operator (#) in C

    language.language.

    Linkage EditorLinkage Editor Link objective code into executable fileLink objective code into executable file

    (*.(*.objobj *.exe)*.exe)

  • 8/9/2019 8051-CH2 Intro Assemblys2'10

    21/22

    List File For Test Program (Assembly)List File For Test Program (Assembly)

    Opcodes Assembly language

    Address/Program Pointer

  • 8/9/2019 8051-CH2 Intro Assemblys2'10

    22/22

    Terima Kasih,

    Ceria-ceriaSelalu

    &Jumpa

    Lagiiiiii!!!