Assembly Language Programming

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 21

INTRODUCTION

Each personal computer has a microprocessor that manages the


computer's arithmetical, logical and control activities.
Each family of processors has its own set of instructions for
handling various operations like getting input from keyboard,
displaying information on screen and performing various other
jobs. These set of instructions are called 'machine language
instruction‘ Processor understands only machine language instructions
which are strings of 1s and 0s. However machine language is too obscure
and complex for using in software development. So the low level
assembly language is designed for a specific family of processors that
represents various instructions in symbolic code and a more
understandable form
Advantages of Assembly Language
An understanding of assembly language provides knowledge of:
1 Interface of programs with OS, processor and BIOS.
2 Representation of data in memory and other external devices.
3 How processor accesses and executes instruction.
4 How instructions accesses and process data.
5 How a program access external devices.
Other advantages of using assembly language are:
6 It requires less memory and execution time.
7 It allows hardware-specific complex jobs in an easier way.
8 It is suitable for time-critical jobs.
Basic Features of PC Hardware
The main internal hardware of a PC consists of the processor,
memory and the registers. The registers are processor
components that hold data and address. To execute a program
the system copies it from the external device into the internal
memory. The processor executes the program instructions.
The fundamental unit of computer storage is a bit; it could be
on (1) or off (0). A group of nine related bits makes a byte.
Eight bits are used for data and the last one is used for parity.
According to the rule of parity, number of bits that are on (1) in
each byte should always be odd.
So the parity bit is used to make the number of bits in a byte
odd. If the parity is even, the system assumes that there had
been a parity error (though rare) which might have caused due
to hardware fault or electrical disturbance.
Basic Features of PC Hardware
The processor supports the following data sizes:
1.Word: a 2-byte data item
2. Doubleword: a 4-byte (32 bit) data item
3. Quadword: an 8-byte (64 bit) data item
4. Paragraph: a 16-byte (128 bit) area
5. Kilobyte: 1024 bytes
6. Megabyte: 1,048,576 bytes
Advantages of High-Level Languages
High-level languages are preferred to program applications,
as they provide a convenient abstraction of the underlying
system suitable for problem solving. Here are some
advantages of programming in a high-level language:
1. Program development is faster. Many high-level
languages provide structures (sequential, selection,
iterative) that facilitate program development. Programs
written in a high-level language are relatively small
compared to the equivalent programs written in an
assembly language. These programs are also easier to code
and debug.
Advantages of High-Level Languages
2. Programs are easier to maintain: Programming a new
application can take from several weeks to several months
and the life cycle of such an application software can be
several years. Therefore, it is critical that software
development be done with a view of software
maintainability, which involves activities ranging from
fixing bugs to generating the next version of the software.
Programs written in a high-level language are easier to
understand and, when good programming practices are
followed, easier to maintain. Assembly language
programs tend to be lengthy and take more time to code
and debug. As a result, they are also difficult to maintain.
Advantages of High-Level Languages
3. Programs are portable: High-level language
programs contain very few processor-
dependent details. As a result, they can be used
with little or no modification on different
computer systems. By contrast, assembly
language programs are processor-specific.
Why Program in the Assembly Language?
Many people see programming in the assembly
language as unnecessary evil. However, there
are two main reasons why programming is still
done in the assembly language: (1) efficiency,
and (2) accessibility to system hardware.
Efficiency refers to how “good” a program is in
achieving a given objective. Here we consider
two objectives based on space (space
efficiency) and time (time efficiency).
Why Program in the Assembly Language?
Space efficiency refers to the memory requirements of a
program, i.e., the size of the executable code. Program A
is said to be more space-efficient if it takes less memory
space than program B to perform the same task. Very
often, programs written in an assembly language tend to
be more compact than those written in a high-level
language. Time efficiency refers to the time taken to
execute a program. Obviously a program that runs faster
is said to be better from the time-efficiency point of
view. If we craft assembly language programs carefully,
they tend to run faster than their high-level language
counterparts
Why Learn the Assembly Language?
• Programming in the assembly language is a tedious
and error-prone process. The natural preference of a
programmer is to program in some high-level
language. We discussed a few good reasons why some
applications cannot be programmed in a high-level
language. Even these applications do not require the
whole program to be written in the assembly language.
In such instances, a small part of the program is written
in the assembly language and the rest is written in
some high-level language. Such programs are called
hybrid or mixed-mode programs.
Why Learn the Assembly Language?
Learning the assembly language has both practical and
educational purposes. Even if you don’t intend to
program in an assembly language, studying it gives you
a good understanding of computer systems. When
you program in a high-level language, you are provided
only a “black-box” view of the system. When
programming in the assembly language, you need to
understand the internal details of the system (for
example, you need to know about processor internal
registers). To understand the assembly language is to
understand the computer system itself!
Why Learn the Assembly Language?
• In this course, you will be exposed to the
assembly languages of both CISC and RISC
processors. We use the popular Pentium
processor to represent the CISC category. We
study RISC processors by looking at the MIPS
assembly language. Studying these two assembly
languages gives you a solid foundation to
understand the differences between the CISC and
RISC design philosophies and how they impact
execution speed of your programs.
Assembly Basic Syntax
An assembly program can be divided into three sections:
1 The data section
2 The bss section
3 The text section
The data section: The data section is used for declaring
initialized data or constants. This data does not change at runtime. You
can declare various constant values, file names or buffer size etc. in
this section.
The syntax for declaring data section is:
section .data
Assembly Basic Syntax

The bss Section: The bss section is used for


declaring variables.
The syntax for declaring bss section is:
section .bss

The text section: The text section is used for keeping the actual
code. This section must begin with the declaration global main, which tells
the kernel where the program execution begins.
The syntax for declaring text section is:
section .text
global main
Main:
Assembly Basic Syntax
Comments:
Assembly language comment begins with a semicolon (;). It may
contain any printable character including blank. It can appear
on a line by itself, like:
; This program displays a message on screen
or, on the same line along with an instruction, like:
add eax ,ebx ; adds ebx to eax
Assembly Language Statements
Assembly language programs consist of three types of statements :
1. Executable instructions or instructions
2. Assembler directives or pseudo-ops
3. Macros
The executable instructions or simply instructions tell the
processor what to do. Each instruction consists of an operation
code (opcode). Each executable instruction generates one
machine language instruction. The assembler directives or
pseudo-ops tell the assembler about the various aspects of the
assembly process. These are non-executable and do not
generate machine language instructions.
Macros are basically a text substitution mechanism.
Syntax of Assembly Language Statements
Assembly language statements are entered one statement
per line. Each statement follows the following format:
[label] mnemonic [operands] [;comment]
The fields in the square brackets are optional. A
basic instruction has two parts, the first one is the
name of the instruction (or the mnemonic) which
is to be executed, and the second are the
operands or the parameters of the command.
Following are some examples of typical assembly
language statements:
Syntax of Assembly Language Statements
Symbols / Labels
Symbols:
– Symbols are used as labels, constants, and substitution values
–  Symbols are stored in a symbol table
–  A symbol name l
i  is a string of up to 200 alphanumeric characters (A-Z, a-z, 0-9,
$, and _)
ii cannot contain embedded blanks
iii first character cannot be a number
iv  case sensitive
–  Symbols used as labels become symbolic addresses that are
associated with locations in the program
Label Field
Labels are symbols
–  Labels must begin in column 1.
–  A label can optionally be followed by a colon
–  The value of a label is the current value of the
Location Counter (address within program)
–  A label on a line by itself is a valid statement
–  Labels used locally within a file must be
unique
Performance: C Versus Assembly Language
Now let us write programs in assembly language. As an
example, consider multiplying two 16-bit integers. Our
strategy is to write the multiplication procedure in C (a
representative of high-level language) and in the
Pentium assembly language and compare their
execution times.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy