assembly language. assembler and compiler pascal a program compiler version a assembly language...

27
ASSEMBLY LANGUAGE

Upload: domenic-eaton

Post on 29-Dec-2015

250 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ASSEMBLY LANGUAGE. Assembler and Compiler Pascal A Program Compiler Version A Assembly Language Versiion A Machine Code Actual version that will be executed

ASSEMBLY LANGUAGE

Page 2: ASSEMBLY LANGUAGE. Assembler and Compiler Pascal A Program Compiler Version A Assembly Language Versiion A Machine Code Actual version that will be executed

Assembler and CompilerPascal A Program

Compiler

Version A Assembly Language

Versiion A Machine Code

Actual version that will be executed

Assembler

Relation between high level language and low level language

Page 3: ASSEMBLY LANGUAGE. Assembler and Compiler Pascal A Program Compiler Version A Assembly Language Versiion A Machine Code Actual version that will be executed

Advantage of Assembly Language Programming Supply more control in controlling

certain devices Execute more compact and smaller

execution module Faster execution time

Page 4: ASSEMBLY LANGUAGE. Assembler and Compiler Pascal A Program Compiler Version A Assembly Language Versiion A Machine Code Actual version that will be executed

Assembly Language Program Execution

Library

Editor:Wite assembly language program

Source code

Assembler

Object Code

Linker

Execution Code

Execution

Page 5: ASSEMBLY LANGUAGE. Assembler and Compiler Pascal A Program Compiler Version A Assembly Language Versiion A Machine Code Actual version that will be executed

Assemble Language Syntax

There are two types of statement– Instruction: example MOV and ADD, which

translated by assembler into machine code– Pointer : instruct assembler to execute

specific work such as create procedure to allocate memory space for variable

Page 6: ASSEMBLY LANGUAGE. Assembler and Compiler Pascal A Program Compiler Version A Assembly Language Versiion A Machine Code Actual version that will be executed

[LABEL/NAME] OPERATION [OPERANd] [;COMMENT]

Statement example:– Pointer: MAIN PROC ;operation name– Instruction: MOV AX,O ;opepration,2

operand Can be seen that assemble language instruction

is in a form ofOPERATION CODE OPERAND

Assemble Language Syntax

Page 7: ASSEMBLY LANGUAGE. Assembler and Compiler Pascal A Program Compiler Version A Assembly Language Versiion A Machine Code Actual version that will be executed

Name/Label Field Used to name instruction, procedure

name or variable name Length from 1-31 character Able to contain character,number and

special character like ? . @ _ $ %. Empty space is not allowed and special

character must be at the beginning of a name

Page 8: ASSEMBLY LANGUAGE. Assembler and Compiler Pascal A Program Compiler Version A Assembly Language Versiion A Machine Code Actual version that will be executed

Name/Label Field

Example of valid name– KAUNTER1– @aksara– JUMLAH_DIGIT– $100– OK?– .CUBA

Example of invalid name– DUA PERKATAAN

(empty space)– 3abc(first character

is a number)– A42.05(“.” is not the

first character)

Page 9: ASSEMBLY LANGUAGE. Assembler and Compiler Pascal A Program Compiler Version A Assembly Language Versiion A Machine Code Actual version that will be executed

Operation Field For instruction, contains

operation code (opcode) in mnemonics form (combination of unique characters)

Assembler will translate the symbolic operation code into machine language operation/opcode

Opcode example is MOV, ADD and SUB.

For directive, contains pseudo operation code (pseudo-op)

Will not be translated into machine code but only inform assembler to do something

Page 10: ASSEMBLY LANGUAGE. Assembler and Compiler Pascal A Program Compiler Version A Assembly Language Versiion A Machine Code Actual version that will be executed

Operand Field For instruction, operand field specifies data

that will be executed by operation Can contain 0, 1 or 2 operand For 2 operand, operand 1 is the destination

operand (consist of register or memory location where result is stored)

Second operand is the source operand

Page 11: ASSEMBLY LANGUAGE. Assembler and Compiler Pascal A Program Compiler Version A Assembly Language Versiion A Machine Code Actual version that will be executed

Comment Field

Increase program understandability Start with ; sign Can contain printed character including

empty space Example:

• ; this is a comment

Page 12: ASSEMBLY LANGUAGE. Assembler and Compiler Pascal A Program Compiler Version A Assembly Language Versiion A Machine Code Actual version that will be executed

Program Data

Assemble translate all data representation into binary number form

In assembly language programming, data can be represented in binary, decimal, hexadecimal and character form

Page 13: ASSEMBLY LANGUAGE. Assembler and Compiler Pascal A Program Compiler Version A Assembly Language Versiion A Machine Code Actual version that will be executed

Number

Written in bit sequence followed by “B” or “b” (optional)

Similar for hexa and decimal number

Example: Valid representation

– 11011 (Decimal)– 11011B (Binary)– -2322D (Decimal)

Invalid representation– 1,234 (contains non digit

character)– 1B4D (there is no B in

decimal number)

Page 14: ASSEMBLY LANGUAGE. Assembler and Compiler Pascal A Program Compiler Version A Assembly Language Versiion A Machine Code Actual version that will be executed

Character

Must written in bracket ‘ ’ or “ ” Will be translated by assembler into

equivalen ASCII Example: the usage of “A” is similar to

41h (ASCII code for “A”)

Page 15: ASSEMBLY LANGUAGE. Assembler and Compiler Pascal A Program Compiler Version A Assembly Language Versiion A Machine Code Actual version that will be executed

Pseudo-op Pseudo-op defination

Pseudo-op Defined as

DB Define byte

DW Define word

DD Define doubleword (2 words)

DQ Define quadword (4 words)

Page 16: ASSEMBLY LANGUAGE. Assembler and Compiler Pascal A Program Compiler Version A Assembly Language Versiion A Machine Code Actual version that will be executed

Variable

Each variable contains data type and address which will be accumulated by program

Declared as– name DB first-value– name DW last-value

Page 17: ASSEMBLY LANGUAGE. Assembler and Compiler Pascal A Program Compiler Version A Assembly Language Versiion A Machine Code Actual version that will be executed

i. Byte Variable– Statement for declaration is in a form of

name DB first-value

– Eg: ALPHA DB 4

– One space with 1 byte size will be prepared with ALPHA and started with value 4

– DUP instruction (duplicate) – for copy all character following the given number without repeated writing

– Eg:• DATA1 DB OFFH,OFFH,OFFH,OFFH is written as

• DATA1 DB 4 DUP (OFFH)

Page 18: ASSEMBLY LANGUAGE. Assembler and Compiler Pascal A Program Compiler Version A Assembly Language Versiion A Machine Code Actual version that will be executed

ii. Word Variable

Statement for define is in a form ofnameDW first-value

example:

WRD DW -2

Page 19: ASSEMBLY LANGUAGE. Assembler and Compiler Pascal A Program Compiler Version A Assembly Language Versiion A Machine Code Actual version that will be executed

Array

One memory sequence whether in byte or word

Eg: for 3-byte array definition B_ARRAY which give starting value of 10h, 20h and 30h is written as

• B_ARRAY DB 10H, 20H, 30H

Page 20: ASSEMBLY LANGUAGE. Assembler and Compiler Pascal A Program Compiler Version A Assembly Language Versiion A Machine Code Actual version that will be executed

Let say an assemble prepare offset address 0200H into B_ARRAY, memory is as below

Symbol Address Content

B_ARRAY 200H 10H

B_ARRAY 201H 20H

B_ARRAY 202H 30H

Page 21: ASSEMBLY LANGUAGE. Assembler and Compiler Pascal A Program Compiler Version A Assembly Language Versiion A Machine Code Actual version that will be executed

If array DW is used, let say assembler prepare offset address 0300H for W_ARRAY:

W_ARRAY DW 1000, 40, 50, 523Symbol Address Content

W_ARRAY 0300H 1000D

W_ARRAY+2 0302H 40D

W_ARRAY+4 0304H 50D

W_ARRAY+6 0306H 523D

Page 22: ASSEMBLY LANGUAGE. Assembler and Compiler Pascal A Program Compiler Version A Assembly Language Versiion A Machine Code Actual version that will be executed

Character sequence ASCII code array can be seen as a character

sequence Eg:

HURUF DB ‘ABC’

is equivalent to

HURUF DB 41H, 42H, 43H The usage of small letter and capital letter is different Eg :

HURUF DB ‘ABC’ = HURUF DB 41H,42H,43H

HURUF DB ‘abc’ = HURUF DB 61H,62H,63H

Page 23: ASSEMBLY LANGUAGE. Assembler and Compiler Pascal A Program Compiler Version A Assembly Language Versiion A Machine Code Actual version that will be executed

Character and number combination is allowed Eg:

MSGDB ‘HELLO’,0AH,0DH,’$’

is equivalent to

MSG DB 48H,45H,4CH,4FH,0AH,0DH,24H

Page 24: ASSEMBLY LANGUAGE. Assembler and Compiler Pascal A Program Compiler Version A Assembly Language Versiion A Machine Code Actual version that will be executed

Constant

Symbolic name is given to the used constant

EQU (equates) instruction is used Syntax : name EQU constant Statement example

LF EQU 0AH This statement accumulate LF name to

0AH (ASCII code) for line feed.

Page 25: ASSEMBLY LANGUAGE. Assembler and Compiler Pascal A Program Compiler Version A Assembly Language Versiion A Machine Code Actual version that will be executed

All 0AH usage can be replaced with LF and give the same result

Example:– MOV DL, 0AH

and– MOV DL, LF

Page 26: ASSEMBLY LANGUAGE. Assembler and Compiler Pascal A Program Compiler Version A Assembly Language Versiion A Machine Code Actual version that will be executed

Symbol at the right of EQU can be character sequence

Example:

PROMPT EQU “TAIP NAMA ANDA” Statement

MSG DB PROMPT

give equivalent result as

MSG DB “TAIP NAMA ANDA” There is no memory space for EQU instruction

Page 27: ASSEMBLY LANGUAGE. Assembler and Compiler Pascal A Program Compiler Version A Assembly Language Versiion A Machine Code Actual version that will be executed

Program structure

Code, data and stack is structured as program segments

Will be translated into memory segment by assembler