assembly programming sir joseph lindo university of the cordilleras

31
Joseph L. Lindo Assembly Programming Sir Joseph Lindo University of the Cordilleras

Upload: anahid

Post on 09-Jan-2016

24 views

Category:

Documents


2 download

DESCRIPTION

Assembly Programming Sir Joseph Lindo University of the Cordilleras. Assembly Programming. Definition. Section 1. Assembly Language. Low level language Instruction mnemonics (Instruction Set) that have a one-to-one correspondence to machine language - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Assembly  Programming  Sir Joseph  Lindo University of the Cordilleras

Joseph L. Lindo

Assembly Programming

Sir Joseph LindoUniversity of the Cordilleras

Page 2: Assembly  Programming  Sir Joseph  Lindo University of the Cordilleras

Joseph L. Lindo

Set-up

Basics

Section 1

Assembly Programming

Assembly Language• Low level language

• Instruction mnemonics (Instruction Set) that have a one-to-one correspondence to machine language

•Calls functions written at the operating system level

Definition

Page 3: Assembly  Programming  Sir Joseph  Lindo University of the Cordilleras

Joseph L. Lindo

Set-up

Basics

Section 1

Assembly Programming

Assembly Applications• Business application for single platform

•Hardware device driver

•Business application for multiple platforms

•Embedded systems & computer games

Definition

Page 4: Assembly  Programming  Sir Joseph  Lindo University of the Cordilleras

Joseph L. Lindo

Set-up

Basics

Define

Assembly ProgrammingProgrammingEnvironment

Softwares Needed:

• Text Editor• Assembler• Emulator

Set-up

Page 5: Assembly  Programming  Sir Joseph  Lindo University of the Cordilleras

Joseph L. Lindo

Set-up

Basics

Define

Assembly Programming

Running Programs

Set-upSave the TEXT file with extension name .ASM

Ex. Sample.asm

Using the CMD

Compile: - ….\TASM> tasm Sample.asm

Page 6: Assembly  Programming  Sir Joseph  Lindo University of the Cordilleras

Joseph L. Lindo

Set-up

Basics

Define

Assembly Programming

Running Programs

Set-upCreate the executable file - ….\TASM> tlink Sample

Execute -….\TASM> tlink Sample

Page 7: Assembly  Programming  Sir Joseph  Lindo University of the Cordilleras

Joseph L. Lindo

Set-up

Basics

Define

Assembly Programming

Basic Elements

Basics

Page 8: Assembly  Programming  Sir Joseph  Lindo University of the Cordilleras

Joseph L. Lindo

Set-up

Basics

Define

Assembly Programming

Data Definition

Basics

A data definition statements sets aside storage in memory for variable and assign a name to the variable.

Page 9: Assembly  Programming  Sir Joseph  Lindo University of the Cordilleras

Joseph L. Lindo

Assembly Programming

--end--

Sir Joseph LindoUniversity of the Cordilleras

Page 10: Assembly  Programming  Sir Joseph  Lindo University of the Cordilleras

Joseph L. Lindo

Assembly Programming

--end na to--

Sir Joseph LindoUniversity of the Cordilleras

Page 11: Assembly  Programming  Sir Joseph  Lindo University of the Cordilleras

Joseph L. Lindo

Comparison of Assembly to HL

Assembly Language

Page 12: Assembly  Programming  Sir Joseph  Lindo University of the Cordilleras

Joseph L. Lindo

Assemblers

Online Task

Divide the class according to the assemblers below. Members are required to post possible knowledge about the assigned assembler.TASMMASMFASMNASMWASM

Due on February 21, 2012

Page 13: Assembly  Programming  Sir Joseph  Lindo University of the Cordilleras

Joseph L. Lindo

Assembly Link Execute Cycle

Assembly Language

SourceFile

ObjectFile

ListingFile

LinkLibrary

ExecutableFile

MapFile

Output

Step 1: text editor

Step 2:assembler

Step 3:linker

Step 4:OS loader

Page 14: Assembly  Programming  Sir Joseph  Lindo University of the Cordilleras

Joseph L. Lindo

Integer Constants

Basic Elements

Optional leading + or – signBinary, Decimal, Hexadecimal digitsCommon radix characters:

h – hexadecimald – decimalb – binary

Examples: 30d, 6Ah, 42, 1101b

Page 15: Assembly  Programming  Sir Joseph  Lindo University of the Cordilleras

Joseph L. Lindo

Integer Expressions

Basic Elements

Precedence Rule

Examples

Page 16: Assembly  Programming  Sir Joseph  Lindo University of the Cordilleras

Joseph L. Lindo

Character and String Constants

Basic Elements

Enclose character in single or double quotes'A', "x"ASCII character = 1 byte

Enclose strings in single or double quotes"ABC"'xyz'Each character occupies a single byte

Embedded quotes:'Say "Goodnight," Gracie'

Page 17: Assembly  Programming  Sir Joseph  Lindo University of the Cordilleras

Joseph L. Lindo

Reserved Words and Identifiers

Basic Elements

Reserved words cannot be used as identifiersInstruction mnemonics, directives, type attributes, operators, predefined symbols

Identifiers1-247 characters, including digitscase insensitive (by default)first character must be a letter, _, @, or $

Page 18: Assembly  Programming  Sir Joseph  Lindo University of the Cordilleras

Joseph L. Lindo

Directives

Basic Elements

Commands that are recognized and acted upon by the assembler

Not part of the Intel instruction setUsed to declare code, data areas, select memory model, declare procedures, etc.

Different assemblers have different directivesTASM != MASM, for example

Page 19: Assembly  Programming  Sir Joseph  Lindo University of the Cordilleras

Joseph L. Lindo

Directives

Basic Elements

.MODEL

It identifies the size of code and data a program could have

Syntax: <.MODEL> <memory model>

Page 20: Assembly  Programming  Sir Joseph  Lindo University of the Cordilleras

Joseph L. Lindo

Directives

Basic Elements

.STACK

It sets aside a block of memory to store the stack

Syntax: <.STACK> [size]

Page 21: Assembly  Programming  Sir Joseph  Lindo University of the Cordilleras

Joseph L. Lindo

Directives

Basic Elements

.DATA

It contains variables and constants definition

Syntax: <.DATA>

Page 22: Assembly  Programming  Sir Joseph  Lindo University of the Cordilleras

Joseph L. Lindo

Directives

Basic Elements

.CODE

It contains program’s instructions

Syntax: <.CODE>

Page 23: Assembly  Programming  Sir Joseph  Lindo University of the Cordilleras

Joseph L. Lindo

Memory Models

Directives

Page 24: Assembly  Programming  Sir Joseph  Lindo University of the Cordilleras

Joseph L. Lindo

Instructions

Basic Elements

Assembled into machine code by assemblerExecuted at runtime by the CPUMember of the Intel IA-32 instruction setParts:

LabelMnemonicOperandComment

Page 25: Assembly  Programming  Sir Joseph  Lindo University of the Cordilleras

Joseph L. Lindo

Labels

Instructions

Act as place markersmarks the address (offset) of code and data

Data labelmust be unique

Code labeltarget of jump and loop instructions

Follow identifier rules

Page 26: Assembly  Programming  Sir Joseph  Lindo University of the Cordilleras

Joseph L. Lindo

Mnemonics and Operands

Instructions

Instruction Mnemonics"reminder"examples: MOV, ADD, SUB, MUL, INC, DEC

Operandsconstant (immediate value)constant expressionregistermemory (data label)

Page 27: Assembly  Programming  Sir Joseph  Lindo University of the Cordilleras

Joseph L. Lindo

Comments

Instructions

Comments are good!explain the program's purposetricky coding techniquesapplication-specific explanations

Single-line commentsbegin with semicolon (;)

Multi-line commentsbegin with COMMENT directive and a character end with the same character

Page 28: Assembly  Programming  Sir Joseph  Lindo University of the Cordilleras

Joseph L. Lindo

Examples

Instructions

No operandsstc ; set Carry flag

One operandinc ax ; registerinc myByte ; memory

Two operandsadd bx,cx ; register, registersub myByte,25 ; memory, constantadd ax,36 * 25 ; register, expression

Page 29: Assembly  Programming  Sir Joseph  Lindo University of the Cordilleras

Joseph L. Lindo

Defining Variables

Data Definition

Intrinsic Data Type

Page 30: Assembly  Programming  Sir Joseph  Lindo University of the Cordilleras

Joseph L. Lindo

Defining Variables

Data Definition

Syntax

[name] Data Type value [,value] …

Using DUP

name Data Type size DUP (value)

Page 31: Assembly  Programming  Sir Joseph  Lindo University of the Cordilleras

Joseph L. Lindo

Assembly Programming

--end--

Sir Joseph LindoUniversity of the Cordilleras