310 likes | 482 Views
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
E N D
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 • Calls functions written at the operating system level Set-up Basics
Assembly Programming Definition Section 1 Assembly Applications • Business application for single platform • Hardware device driver • Business application for multiple platforms • Embedded systems & computer games Set-up Basics
Assembly Programming Programming Environment Define Set-up Set-up • Softwares Needed: • Text Editor • Assembler • Emulator Basics
Assembly Programming Running Programs Define • Save the TEXT file with extension name .ASM • Ex. Sample.asm • Using the CMD • Compile: • - ….\TASM> tasm Sample.asm Set-up Set-up Basics
Assembly Programming Running Programs Define • Create the executable file • - ….\TASM> tlink Sample • Execute • -….\TASM> tlink Sample Set-up Set-up Basics
Assembly Programming Basic Elements Define Set-up Basics Basics
Assembly Programming Data Definition Define • A data definition statements sets aside storage in memory for variable and assign a name to the variable. Set-up Basics Basics
Assembly Programming --end-- Sir Joseph Lindo University of the Cordilleras
Assembly Programming --end na to-- Sir Joseph Lindo University of the Cordilleras
Assembly Language Comparison of Assembly to HL
Online Task Assemblers Divide the class according to the assemblers below. Members are required to post possible knowledge about the assigned assembler. TASM MASM FASM NASM WASM Due on February 21, 2012
Assembly Language Assembly Link Execute Cycle
Basic Elements Integer Constants • Optional leading + or – sign • Binary, Decimal, Hexadecimal digits • Common radix characters: • h – hexadecimal • d – decimal • b – binary Examples: 30d, 6Ah, 42, 1101b
Basic Elements Integer Expressions • Precedence Rule Examples
Basic Elements Character and String Constants • 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'
Basic Elements Reserved Words and Identifiers • Reserved words cannot be used as identifiers • Instruction mnemonics, directives, type attributes, operators, predefined symbols • Identifiers • 1-247 characters, including digits • case insensitive (by default) • first character must be a letter, _, @, or $
Basic Elements Directives • Commands that are recognized and acted upon by the assembler • Not part of the Intel instruction set • Used to declare code, data areas, select memory model, declare procedures, etc. • Different assemblers have different directives • TASM != MASM, for example
Basic Elements Directives .MODEL It identifies the size of code and data a program could have Syntax: <.MODEL> <memory model>
Basic Elements Directives .STACK It sets aside a block of memory to store the stack Syntax: <.STACK> [size]
Basic Elements Directives .DATA It contains variables and constants definition Syntax: <.DATA>
Basic Elements Directives .CODE It contains program’s instructions Syntax: <.CODE>
Directives Memory Models
Basic Elements Instructions • Assembled into machine code by assembler • Executed at runtime by the CPU • Member of the Intel IA-32 instruction set • Parts: • Label • Mnemonic • Operand • Comment
Instructions Labels • Act as place markers • marks the address (offset) of code and data • Data label • must be unique • Code label • target of jump and loop instructions • Follow identifier rules
Instructions Mnemonics and Operands • Instruction Mnemonics • "reminder" • examples: MOV, ADD, SUB, MUL, INC, DEC • Operands • constant (immediate value) • constant expression • register • memory (data label)
Instructions Comments • Comments are good! • explain the program's purpose • tricky coding techniques • application-specific explanations • Single-line comments • begin with semicolon (;) • Multi-line comments • begin with COMMENT directive and a character end with the same character
Instructions Examples • No operands • stc ; set Carry flag • One operand • inc ax ; register • inc myByte ; memory • Two operands • add bx,cx ; register, register • sub myByte,25 ; memory, constant • add ax,36 * 25 ; register, expression
Data Definition Defining Variables • Intrinsic Data Type
Data Definition Defining Variables • Syntax • [name] Data Type value [,value] … • Using DUP • name Data Type size DUP (value)
Assembly Programming --end-- Sir Joseph Lindo University of the Cordilleras