Presentation is loading. Please wait.

Presentation is loading. Please wait.

INTRODUCTION ABOUT ASSEMBLY

Similar presentations


Presentation on theme: "INTRODUCTION ABOUT ASSEMBLY"— Presentation transcript:

1 INTRODUCTION ABOUT ASSEMBLY

2 Who am I? Name: Dina Al-Bassam
Office: 2nd floor, Office Hours: Sun: , 12:30-1:30 Wed: 12:30-2:30 Thu: 11-1:30

3 Grade 10 Project 5 Lab work Participation Final lab

4 What is assembly language
Each personal computer has a microprocessor that manages the computer's activities. Each processor has its own set of instructions for handling various operations such as getting input from keyboard, displaying information on screen. These set of instructions are called 'machine language instructions’ written in 0 and 1. However, machine language is too obscure and complex for using in software development. 4

5 What is assembly language
Assembly language is a low-level programming language for a computer. Each statement is [almost] exactly equivalent to one machine instruction. 4

6 Advantages of Assembly Language
Studying assembly language is possible to gain a feeling for the way the computer "thinks" and why certain things happen the way they do inside the computer. Writing assembly language programs is efficient because assembly language is so close to machine language so produces a faster , shorter machine language program. It is suitable for complex and time-critical jobs. 4

7 Difference between high level language and assembly level language
Assembly language High level language Difficult to read and understand Easier to read and understand Readability No , designed for a specific family of processors Yes Portable Each statement is [almost] one machine instruction Each statement need many machine instruction Number of equivalent machine code MOV AX,6 ADD AX,Y MOV A,AX X=6+Y Example 4

8 Outline Creating and Running a Program Assembly Language Statements
Defining Types of data Numeric Constant Named Constants Program Structure 1

9 Creating and Running a Program
A text editor or word processor is used to create a source program file. Editor .ASM file An assembler is used to translate the source file into a machine language object file. Assembler .OBJ file A linker is used to link one or more object files to create a run file. Linker .EXE file 2

10 Creating and Running a Program
Assembling: translate source program (written in assembly language) into machine code (object code) Linking: complete machine code for the object program, generate an executable module

11 Assembling & Linking the program
After printing the copyright information, the assembler will check the source file for syntax errors: If one or more errors were found: The assembler will display the line number of each error and a short description. If no errors were found: The assembler will translate the assembly language code into the assembly machine language object file (.obj file). The linker will take one or more object files, fills any missing addresses, and combines the object files into a single executable file (.exe file). 6

12 Assembly Language Statements
Programs consist of statements, one per line. Statements is either instruction or assembler directive. Instruction , which the assembler translate into machine code. Assembler directive, which instructs the assembler to perform some specific task. Both instructions and directives have up to four fields: [identifier ] operation [operand(s)] [comment] At least one blank or tab character must separate the fields. The fields do not have to be aligned in a particular column, but they must appear in the above order. 4

13 Assembly Language Statements
An example of an instruction: START: MOV CX,5 ; initialize counter An example of an assembler directive: MAIN PROC

14 Identifier field The identifier is used for instruction labels, procedure names and variable name. Can be from 1 to 31 characters long (not case sensitive). May consist of letters, digits, and the special characters ? _ $ % (Thus, embedded blanks are not allowed). Names must not begin with a digit. If a dot is used, it must be the first character.

15 Identifiers Examples: COUNTER1 2abc Begins with a digit @CHARACTER
. Not first character TWO WORDS Contains a blank STD_NUM .TEST YOU&ME Contains an illegal character 8

16 Operation field For an instruction, the operation field contains a symbolic operation code (opcode). The assembler translates a symbolic opcode into machine language. For example: mov, add , sub. For an assembler directive, the operation field contains a pseudo-operation code (pseudo-op). pseudo-op are not translated into machine code, they simply tell assembler to do something. For example: DB , DW , PROC.

17 Operand field For an instruction, the operand fields specifies the data that are to be acted on by the operation. An instruction may have zero, one, two operands.

18 Comment field The comment field of a statement is used by the programmer to say something about what the statement does. A semicolon marks the beginning of this field, and the assembler ignores anything typed after the semicolon. It is almost impossible to understand an assembly language program without comments. Good programming practice dictates a comment on almost every line. Examples: MOV CX, 0 ; CX counts terms, initially 0 13

19 Defining Types of data Name: defined the variable name
expression Dn [name] expression Dn [name] Name: defined the variable name Dn (Directive): define the data item (type or space) Expression: is an operand may specify an uninitialized value or constant value an uninitialized value defined by item ? EXAMPLE : DATAX DB ?

20 Defining Types of data (Directive):
Pseudo-op Stands for DB Define Byte DW Define Word DD Define Doubleword DQ Define Quadword DT Define Tenbytes Data types are not static types like in java int, they are operation, DB, go assembler and define variable as byte for me

21 Defining Types of data -Examples
a memory byte is associated with the name ALPHA, and initialized to 4 ALPHA DB 4 A memory byte is associated with the name BYT, and uninitialized. BYT DB ? a memory word is associated with the name WRD, and initialized to -2. WRD DW -2

22 High and Low Bytes of a Word
WORD1 DW 1234H high byte WORD1+1 low byte WORD1

23 Defining Types of data The decimal range (fit a byte):
Unsigned representation: 0 to 255 Signed representation: -128 to 127 The decimal range (fit a word): Unsigned representation: 0 to 65535 Signed representation: to 32767

24 Defining Types of data – Array byte
an array is a sequence of memory bytes or words. Example: B_ARRAY DB 10H,20H,30H Symbol Address Contents B_ARRAY H 10H B_ARRAY H 20H B_ARRAY H 30H

25 Defining Types of data – Array word
Example: W_ARRAY DW ,40,29887,329 Symbol Address Contents W_ARRAY H D W_ARRAY H D W_ARRAY H D W_ARRAY H D

26 Defining Types of data :The DUP Operator
It is possible to define arrays whose elements share a common initial value by using the DUP (duplicate) operator. Syntax: Example: Repeat-count(exp) Dn [name] creates an array of 212 uninitialized bytes. DELTA DB 212 DUP (?) set up an array of 100 words, with each entry initialized to 0. GAMMA DW 100 DUP (0)

27 Character String ASCII codes can be initialized with a string of characters using single quotes like ‘PC’ or double quotes like “PC”. Example: LETTERS DB 'ABC' = LETTERS DB 41H,42H,43H Inside a string, the assembler differentiates between upper and lowercase. It is possible to combine characters and numbers in one definition: Example: MSG DB 'HELLO',0AH,0DH, '$'

28

29 Numeric Constant In an assembly language program we may express data as: Binary: bit string followed by ‘B’ or ‘b’ Decimal: string of decimal digits followed by an optional ‘D’ or ‘d’ Hex: begins with a decimal digit and ends with ‘H’ or ‘h’ Octal : end with ‘O’ or ‘o’ Any number may have an optional sign.

30 Numeric Constant Number Type 11011 1101B 64223 decimal -21843D 1B4DH
FFFFH 0FFFFH decimal binary decimal decimal hex illegal illegal hex

31 Named Constants - EQU (Equates)
To assign a name to a constant, we can use the EQU pseudo-op. Syntax: name EQU constant Examples: LF EQU 0AH MOV DL,0AH = MOV DL,LF PROMPT EQU 'Any Thing' MSG DB 'Any Thing' = MSG DB PROMPT Note: no memory is allocated for EQU names.

32 Directives SEGMENT Directive Data Segment Stack segment Code Segment
END Directive ex: ENDP directive ends a procedure ex: END directive ends the entire program and appears as the last statement 9

33 Program Structure - Memory Models
The size of code and data a program can have is determined by specifying a memory model using the .MODEL directive. Syntax: .MODEL memory_model Model Description SMALL code in 1 segment data in 1 segment MEDIUM code > 1 segment data in 1 segment COMPACT code in 1 segment data > 1 segment LARGE code > 1 segment data > 1 segment no array larger than 64k bytes HUGE code > 1 segment data > 1 segment arrays may be larger than 64k bytes

34 Program Structure - Memory Models
The appropriate model is SMALL, unless there is a lot of code or data. .MODEL directive should come before segment definitions. A segment is 216 (64 k)

35 Program Structure - Stack Segment
The purpose of the stack segment declaration is to set aside a block of memory (the stack area) to store the stack. The stack area should be big enough to contain the stack at its maximum size. Syntax: .STACK size ; where size is an optional number that specifies ; the stack area size in bytes. Example: .STACK 100H ; sets aside 100H bytes for the stack area. ; (reasonable size for most applications). If size is omitted, 1KB is set aside for the stack area.

36 Program Structure - Data Segment
A program’s data segment contains all the variable definitions. Constant definitions are often made here as well. (they may be placed elsewhere in the program since no memory allocation is involved). To declare a data segment, we use the directive .DATA, followed by variable and constant declarations. Example: .DATA WORD1 DW 2 MSG DB ‘this is a message’

37 Program Structure - Code Segment
The code segment contains a program’s instructions. Syntax: .CODE name ; where name is an optional name of segment. There is no need for a name in a SMALL program. Inside a code segment, instructions are organized as procedures.

38 Program Structure - Code Segment
The simplest procedure definition is: name PROC ; name: is the name of the procedure. ; body of the procedure ; PROC & ENDP: are pseudo-ops that name ENDP ; delineate the procedure Example of a code segment definition: .CODE MAIN PROC ; main procedure instructions MAIN ENDP ; other procedures go here

39 A General Form of a .SMALL model program
Program Structure - A General Form of a .SMALL model program .MODEL SMALL .STACK 100H .DATA ; data definitions go here .CODE MAIN PROC ; instructions go here MAIN ENDP ; other procedures go here END MAIN


Download ppt "INTRODUCTION ABOUT ASSEMBLY"

Similar presentations


Ads by Google