+ All Categories
Home > Documents > Lecture 1 Chapter 4 –Requirements for coding in Assembly Language

Lecture 1 Chapter 4 –Requirements for coding in Assembly Language

Date post: 21-Jan-2016
Category:
Upload: maegan
View: 27 times
Download: 2 times
Share this document with a friend
Description:
Lecture 1 Chapter 4 –Requirements for coding in Assembly Language. Chapter Outline Assembly Language Features Simplified segment Directive Defining Types of data Equate Directive. 1. Assembly Language Features. Program comments Reserved words Identifiers Statements Directives. 4. - PowerPoint PPT Presentation
19
Lecture 1 Chapter 4 –Requirements for coding in Assembly Language
Transcript
Page 1: Lecture 1 Chapter 4 –Requirements for coding in Assembly Language

Lecture 1Chapter 4 –Requirements for coding in Assembly

Language

Page 2: Lecture 1 Chapter 4 –Requirements for coding in Assembly Language

1

Chapter Outline

Assembly Language Features

Simplified segment Directive

Defining Types of data

Equate Directive

Page 3: Lecture 1 Chapter 4 –Requirements for coding in Assembly Language

4

Assembly Language Features

• Program comments•Reserved words•Identifiers•Statements•Directives

Page 4: Lecture 1 Chapter 4 –Requirements for coding in Assembly Language

13

Program Comment

• 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.

Page 5: Lecture 1 Chapter 4 –Requirements for coding in Assembly Language

14

Program Comment

• Thus, comments is used to put the instruction into the context of the program.

• Examples:•MOV CX, 0 ; CX counts terms, initially 0

• It is permissible to make an entire line a comment, and to use them to create space in a program.

Page 6: Lecture 1 Chapter 4 –Requirements for coding in Assembly Language

Reserved words

Instructions, such as MOV and ADD

Directives, such as END that used to provide

information to the assembler

Operators

Predefined symbols, such as @Data, which return

information to your program during the assembly

Page 7: Lecture 1 Chapter 4 –Requirements for coding in Assembly Language

Identifiers

Two types of Identifiers : name and label

1. Name refers to the address of a data items

ex: COUNTER ,SUM,ID

2. Label refers to the address of an

instruction,procedure,or segment

ex: MAIN

Page 8: Lecture 1 Chapter 4 –Requirements for coding in Assembly Language

Identifiers

•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 may not begin with a digit.

•If a dot is used, it must be the first character.

Page 9: Lecture 1 Chapter 4 –Requirements for coding in Assembly Language

8

Identifiers

• Examples:

• COUNTER1

• 2abc

• @CHARACTER

• A45. 28

• TWO WORDS

• STD_NUM

• .TEST

Begins with a digit

. Not first character

Contains a blank

• YOU&ME Contains an illegal character

Page 10: Lecture 1 Chapter 4 –Requirements for coding in Assembly Language

6

Statements

• 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.

• An example of an instruction: START: MOV CX,5 ; initialize counter

• An example of an assembler directive: MAIN PROC

• [Name Fields are optional]

Page 11: Lecture 1 Chapter 4 –Requirements for coding in Assembly Language

9

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

Page 12: Lecture 1 Chapter 4 –Requirements for coding in Assembly Language

9

SIMPLIFIED SEGMENT 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 statment

Page 13: Lecture 1 Chapter 4 –Requirements for coding in Assembly Language

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 DescriptionSMALL code in 1 segment data in 1 segmentMEDIUM code > 1 segment data in 1 segmentCOMPACT code in 1 segment data > 1 segmentLARGE code > 1 segment data > 1 segment

no array larger than 64k bytesHUGE code > 1 segment data > 1 segment

arrays may be larger than 64k bytes

Page 14: Lecture 1 Chapter 4 –Requirements for coding in Assembly Language

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)

Page 15: Lecture 1 Chapter 4 –Requirements for coding in Assembly Language

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.

Page 16: Lecture 1 Chapter 4 –Requirements for coding in Assembly Language

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’

Page 17: Lecture 1 Chapter 4 –Requirements for coding in Assembly Language

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, However, the assembler will generate an error.

• Inside a code segment, instructions are organized as procedures.

Page 18: Lecture 1 Chapter 4 –Requirements for coding in Assembly Language

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

Page 19: Lecture 1 Chapter 4 –Requirements for coding in Assembly Language

Program Structure - A General Form of a .SMALL model program

.MODEL SMALL

.STACK 100H

.DATA; data definitions go here.CODEMAIN PROC; instructions go hereMAIN ENDP; other procedures go hereEND MAIN


Recommended