0% found this document useful (0 votes)
29 views47 pages

Fundamentals of Assembly Language: Julius Bancud

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1/ 47

Fundamentals of

Assembly Language
Julius Bancud
Programming Language

• A programming language is a notation for


expressing instructions to be carried out by the
computer. It is a medium of communication
between the human and the machine, and then
between one human being and another.
Classification of Programming
Language
The proliferation of computer programming
languages continues to this very day. There have
probably been more than 3,000 programming
languages designed and implemented, although many
of these have been used exclusively for “ in house”
production rather than marketed for commercial use.
Programming languages can be classified as :
Classification of Programming
Language
a. High Level Languages – is an English-like
language that provides for more natural expression of
algorithms. It is usually designed to handle a
particular application area efficiently. It can express
the same program as low-level language, but with
less detail and fewer lines of code. Languages like
BASIC, PASCAL, COBOL and JAVA are some of the
examples of high-level language.
Classification of Programming
Language
2. Mid-Level Language – it is computer language which
combine low-level efficiency with high-level language
structure, abstraction and portability. Examples of mid-
level language include C and Modula-2
3. Low-Level Language – is considered to be machine-
oriented since it is closely follows the built in instruction
set of the underlying computer. Assembly and machine
languages are common examples of low-level language.
Language Translator

Language Translator
- it is known as language processor. Language
translator is a software that accepts source program
coded in high/mid-level language as input and
produces the equivalent machine language
instruction.
Types of Language Translator
1. Compiler
-a compiler is a translator program that transform and entire
source program composed of high/mid-level language statements
into an object program consisting of machine language
executable code.
High/Mid-level language machine language
Compiler
source program instruction
Types of Language Translator

2. Interpreter
- an interpreter processes the source program on a statement-
by-statement basis. It translates high/mid-level languages
statements and then executes it one statement at a time.

High/Mid level language machine


Interpreter
source program language instruction
Types of Language Translator

3. Assembler
-an assembler is a language translator that transforms
assembly language to machine language instruction

Assembly language machine language


ASSEMBLER

Source program instruction


Linker
Linker – is a computer program for high, mid and low levels of
programming language that completes the process by converting the
object code into executable machine code
Advantages of Assembly Language
Despite the fact that coding in high-level language is more
productive, some advantages of using assembly language are as
follows:
1. It provides more control over handling hardware equipment.
2. It generates smaller, more compact executable modules.
3. It results in faster execution.
Requirement for coding
Assembly Language
Comment
- Is a part of a program that is ignored by the
assembler. Though optional, the use of comments
throughout a program can improve its readability and
clarity especially in assembly language where the
purpose of a set of instruction is often ambiguous. It
begins with a semicolon (;) and whenever you code it,
the assembler assumes that all characters to its right
side is a comment.
Ways to include comment

• Any statement whose first non-blank character is a


semicolon.
Example:
; this program displays Hello, world!
• At the end of an instruction
Example:
MOV AX, 8053h ; initializes the value of AX to 8053h
Reserved Words
These are words in which the assembler assigns a special meaning
and it cannot be used as identifiers. They are reserved for their own
purpose to be used only under special condition. Using them for a
wrong purpose causes the assembler to generate an error message.
Categories of Reserved Words
• INSTRUCTIONS – these are statement that will be translated
into machine language and executed by the computer.
Examples:
MOV ADD SUB MUL DIV INC
DEC LOOP CMP
Directives

• DIRECTIVES – these are statements that give


information to the assembler. Sometimes directives
are called pseudo-ops. Unlike instructions, directives
are not translated into machine language but they are
necessary for your program to assemble properly.
Examples:
TITLE DOSSEG .MODEL
.STACK .DATA .CODE
Operators

• OPERATORS – these are used at assembly time to


affect the value of an operand. Like directives,
operators are recognized by the assembler and they
don’t correspond to machine instructions
Examples:
OFFSET SIZE LENGTH
PTR MOD +, -, *, /
Pre-Defined Symbols

• PRE-DEFINED SYMBOLS - these are symbols


that return information to your program.
Examples:
@data @model
IDENTIFIER

IDENTIFIER – an identifier is a used defined name


(variable) that you apply to an intern in your program that
you expect to reference.
Types of Identifiers
• Name – it refers to the address of a data item.
Examples:
x db 0
msg db “ Aloha! $”
Label

• Label – it refers to the address of an instruction or procedure.


Examples:
MOV DL, 41
A: INT 21
ADD DL, 20
INT 21
SUB DL, 20
LOOP A
RULES IN CONSTRUCTING
VALID IDENTIFIER
• It must use letters (A..Z, a..z) , numbers (0…9) and/or special characters
like underscore (_), question mark (?) and at sign (@)
• It must always start with a letter.
• It must not use reserved words
• It must not exceed to 31 characters

Examples of valid identifiers: neym r2d2


num_1 msg8
Examples of invalid identifiers: title num-1
4ever
STATEMENT
An assembly language statement program consists of a set of statements. The
two types of statements are instructions and directives. Some general guidelines
for coding a bona fide statement:
• A statement may begin anywhere on the line
• Each line can only contain one statement
• Unlike C language, assembly is not case sensitive. You can use their upper or
lowercase letters.
• Take note that statements can have two operands. A single operand and even
none at all
Examples: ADD AX, BX ; uses two operands
DEC CX ; uses single operand
RET ; no operand
MOST COMMON
DIRECTIVES
• TITLE - It creates a title ( up to 60 characters) of
source listing.
Format:
TITLE <text>
Examples:
TITLE This program displays Kumusta, UDM!
TITLE PROGRAM.ASM
Dosseg
• DOSSEG – it tells the assembler to ignore all other requests and adopt the DOS
segment sequence – stack, data and code
Format:
DOSSEG
.MODEL – It specifies and initializes the memory model before defining any segment.
Format:
.MODEL < memory-model>
Examples:
.MODEL TINY
.MODEL SMALL
.MODEL MEDIUM
Types of Memory Model
MEMORY MODEL NO. OF DATA NO. OF CODE
SEGMENT SEGMENT
Tiny 0 0
Small 1 1
Medium 1 More than 1
Compact More than 1 1
Large More than 1 More than 1
Stack/Data

• STACK – It defines the size of the stack. The default


stack size is 1,024 bytes which you can overrule.
Format:
.STACK size
• DATA – it defines and marks the beginning od data
segment
Format:
.DATA
Code/End

• CODE – it defines and marks the code segment


which consists of a set of instructions.
Format:
.CODE
• END – It is placed at the last line of the source code
Format:
END
FOR DEFINING DATA

DIRECTIVE LENGTH (IN DESCRIPTION


BYTES)
DB 1 Define Byte
DW 2 Define Word
DD 4 Define
DoubleWord
DF 6 Define Farword
DQ 8 Define Quafword
DT 10 Define Tenbytes
String

String – is used for description data such as person’s name or


simply a message. It must end with dollar ($) symbol and
defined in double quotation mark (“ “). DB is a conventional
format for defining string of any length.
Example:
neym db “Louis Vuitton$”
If a string contains a single quote, you can define it this way
Example:
food db “Gerry’s Grill $”
Numeric Constant

• Numeric constant – they are used to define arithmetic values


and memory addresses. It is identified wit a radix specifier
such as d for decimal, b for binary and h for hexadecimal.
Example:
msg db “ Bon jour, monsieur!”, 0Ah, 0Dh, “$”
Is the same with:
msg db “ Bon jour, monsieur!”, 10d, 13d, “$”
msg db “ Bon jour, monsieur!”, 00001010b, 00001101, “$”
Structure of an Assembly Language Program
TITLE MYPROG.ASM
DOSSEG
.MODEL SMALL
.STACK 0100h
.DATA
X DB “ KAMUSTA , Students!!!$”
.CODE
MOV AX, @DATA
MOV DS, AX
MOV AH, 09h
MOV DX, OFFSET X
INT 21H
MOV AX, 4C00h
INT 21h
END
INSTRUCTION FOR
INITIALIZING THE PROGRAM
TITLE MYPROG.ASM
DOSSEG
.MODEL SMALL
.STACK 0100h
.DATA
.CODE
MOV AX, @DATA
MOV DS, AX
INSTRUCTION FOR
CONCLUDING THE PROGRAM

MOV AX, 4C00h


INT 21h
END
1. Displaying a character (“uppercase ‘A’) on
screen.
Output
EXAMPLE 2. Displaying character (lowercase ‘b’)
twice on screen.
Output
EXAMPLE 3. Using control characters( 0A – line feed and 0D – carriage return) in screen display.
Output
Example 4. Displaying the same character (‘uppercase Z’)
thirty times using LOOP on screen.
Output
Displaying different characters (‘A to Z’) using LOOP on the
same line.
Output
Displaying different characters (“0 to 9”) using loop
vertically.
Output
Displaying string (“ computer”) on screen.
Output
ASCII CODE
INT 21h FUNCTIONS

AH = 01h KEYBOARD INPUT. This function waits for you to type a character on
the keyboard. It echoes the character to the screen and returns the ASCII
character in the AL register
AH = 02h DISPLAY OUTPUT. This function displays one character on the screen.
DL = character to display on screen
AH = 08h KEYBOARD INPUT WITHOT ECHO. This function reads a character from
the keyboard but doesn’t display the character on the screen.
AL = Character read from the keyboard.
AH = 09h DISPLAY STRING. This function displays the string pointed to by the
DS:DX pair of registers.
The end of the string should be marked with the $ symbol.
AH = 0AH READ STRING. This function reads the string from the keyboard.
AH = 4Ch EXIT DOS. This function allows you to go back to DOS environment.
AL Return Code
- normally sets to zero (0)

You might also like