Sie sind auf Seite 1von 3

1) Machine Language

Consists of individual instructions that will


be executed by the CPU one at a time
2) Assembly Language (Low Level Language)
Designed for a specific family of processors
(different processor groups/family has
different Assembly Language)
Consists of symbolic instructions directly
related to machine language instructions
one-for-one and are assembled into
machine language.
3) High Level Languages
e.g.: C, C++ and Vbasic
Designed to eliminate the technicalities of a
particular computer.
Statements compiled in a high level
language typically generate many low-level
instructions.
Advantages of Assembly Language
1. Shows how program interfaces with the
processor, operating system, and BIOS.
2. Shows how data is represented and stored
in memory and on external devices.
3. Clarifies how processor accesses and
executes instructions and how instructions
access and process data.
4. Clarifies how a program accesses external
devices.
Reasons for using Assembly Language
1. A program written in Assembly Language
requires considerably less memory and
execution time than one written in a high
level language.
2. Assembly Language gives a programmer
the ability to perform highly technical tasks
that would be difficult, if not impossible in a
high-level language.
3. Although most software specialists develop
new applications in high-level languages,
which are easier to write and maintain, a
common practice is to recode in assembly

Prepared by: Engr. Noviel A. Villamor

Page

Levels of Programming Languages

Introduction to Assembly language programming

language those sections that are timecritical.


4. Resident programs (that reside in memory
while other program execute) and interrupt
service routines (that handle input and
output) are almost always develop in
Assembly Language.
Disadvantages of using Assembly Language
1.Need to know detail hardware
implementation
2. Not portable
3. Slow to development and difficult to
debug
Basic components in assembly Language:

Instruction
Directive
Label
Comment

Assembly Language Statements


Three types of statements in assembly language
Typically, one statement should appear on a line
1. Executable Instructions
-Generate machine code for the processor
to execute at runtime
-Instructions tell the processor what to do
2. Assembler Directives
-Provide information to the assembler while
translating a program
-Used to define data, select memory model,
etc.
-Non-executable: directives are not part of
instruction set
3. Macros
-Shorthand notation for a group of
statements
-Sequence of instructions, directives, or
other macros
Constants
Integer Constants
Examples: 10, 42d, 10001101b, 0FF3Ah,
777o
Radix: b = binary, d = decimal, h =
hexadecimal, and o = octal
If no radix is given, the integer constant is
decimal

[label:] mnemonic [operands]

o
o

No operands
stc
; set carry flag
One operand
inc ax
; increment register ax
call Clrscr
; call procedure Clrscr
jmp L1
; jump to instruction with label
L1
Two operands
add ebx, ecx ; register ebx = ebx + ecx
sub var1, 25 ; memory variable var1 = var1 25
Three operands
imul eax,ebx,5 ; register eax = ebx * 5

[;comment]

Instruction Label (optional)


Marks the address of an instruction, must
have a colon :
Used to transfer program execution to a
labeled instruction
Mnemonic
Identifies the operation (e.g. MOV, ADD,
SUB, JMP, CALL)
Operands
Specify the data required by the operation
Executable instructions can have zero to
three operands
Operands can be registers, memory
variables, or constants
Instructions Examples

Page

A hexadecimal beginning with a letter must


have a leading 0
Character and String Constants
Enclose character or string in single or
double quotes
Examples: 'A', "d", 'ABC', "ABC", '4096'
Embedded quotes: "single quote ' inside",
'double quote " inside'
Each ASCII character occupies a single
byte
Instructions
Assembly language instructions have the
format:

Introduction to Assembly language programming

Not case sensitive


First character must be a letter (A..Z, a..z),
underscore(_), @, ?, or $.
Subsequent characters may also be digits.
Cannot be same as assembler reserved
word.
Comments
Comments are very important!
Explain the program's purpose
When it was written, revised, and by
whom
Explain data used in the program
Explain instruction sequences and
algorithms used
Application-specific explanations
Single-line comments
Begin with a semicolon ; and terminate at
end of line
Multi-line comments
Begin with COMMENT directive and a
chosen character
End with the same chosen character

Registers
Registers are used to control instructions being
executed, to handle addressing of memory, and
to provide arithmetic capability
Registers of Intel Processors can be categorized
into:
1. Segment register
2. Pointer register
3. General purpose register
4. Index register
5. Flag register

General Purpose Registers


1. AX register

Acts as the accumulator and is used in


operations that involve input/output and
arithmetic

2.

BX Register

Known as the base register since it is


the only this general purpose register

Identifiers

Identifier is a programmer chosen name


Identifies variable, constant, procedure,
code label
May contain between 1 and 247 characters

Prepared by: Engr. Noviel A. Villamor

known as count register


may contain a value to control the
number of times a loops is repeated or a
value to shift bits left or right
CX can also be used for many
computations
4. DX Register

Known as data register


Some I/O operations require its use
Multiply and divide operations that
involve large values assume the use of
DX and AX together as a pair to hold the
data or result of operation.
Number of bits and the fractions of the
register is as below :
TITLE and .MODEL Directives

.TITLE line (optional)


Contains a brief heading of the program and the
disk file name
.MODEL directive
Specifies the memory configuration
For our purposes, the FLAT memory model will
be used
Linear 32-bit address space (no segmentation)
STDCALL directive tells the assembler to use
Standard conventions for names and procedure
calls
TITLE and .MODEL Directives
.686 processor directive
Used before the .MODEL directive
Program can use instructions of Pentium P6
architecture
At least the .386 directive should be used with the
FLAT model
.STACK directive

Prepared by: Engr. Noviel A. Villamor

Page

that can be used as an index to extend


addressing.
This register also can be used for
computations
BX can also be combined with DI and SI
register as a base registers for special
addressing like AX, BX is also consists
of EBX, BH and BL
3. CX Register

Introduction to Assembly language programming


Tells the assembler to define a runtime stack for
the program
The size of the stack can be optionally specified
by this directive
The runtime stack is required for procedure calls
.DATA directive
Defines an area in memory for the program data
The program's variables should be defined under
this directive
Assembler will allocate and initialize the storage
of variables
.CODE directive
Defines the code section of a program containing
instructions
Assembler will place the instructions in the code
area in memory
.INCLUDE directive
Causes the assembler to include code from
another file
PROC and ENDP directives
Used to define procedures
As a convention, we will define main as the first
procedure
Additional procedures can be defined after main
END directive
Marks the end of a program
Identifies the name (main) of the programs
startup procedure

Das könnte Ihnen auch gefallen