0% found this document useful (0 votes)
30 views30 pages

CMP 207 Notes 2020

The document outlines the course 'Foundations of Sequential Programming' (CMP 207), focusing on the relationship between high-level languages and computer architecture, particularly in assembly language programming. It covers various programming language classifications, including machine, assembly, high-level, system, scripting, and declarative languages, along with their advantages and disadvantages. The course aims to equip students with practical skills in assembly programming and an understanding of microcomputer architecture and instruction categorization.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views30 pages

CMP 207 Notes 2020

The document outlines the course 'Foundations of Sequential Programming' (CMP 207), focusing on the relationship between high-level languages and computer architecture, particularly in assembly language programming. It covers various programming language classifications, including machine, assembly, high-level, system, scripting, and declarative languages, along with their advantages and disadvantages. The course aims to equip students with practical skills in assembly programming and an understanding of microcomputer architecture and instruction categorization.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 30

Course title: Foundations of sequential programming

Course code: CMP 207, 3 unit course


Course Details
The relationship between high Level Language and Computer Architecture that underlies
their implementation: basic machine architecture assembles specification and translation of
Programming Language Block Structured Languages, parameter passing mechanisms.

Course Description
This course focuses both the theoretical and practical aspect of Assembly Language.
Different classifications of programming languages are identified. Basic architecture of a
microcomputer was also taught. The practical aspect deals with programming in Assembly
language which is carried out in the laboratory. It covers the interactions between different
categories of Assembly programming Language Instructions and registers.

Course Objectives
The main objective of this course is to impact on the students the act of programming
in Assembly language. By the end of the course, students will be able to :
1. Categorize different programming Languages
2. Know the basic microcomputer architecture and their functions
3. Categorize different assembly programming Language Instructions
4. Have the understanding of programming that interact with machine architecture which
including register sections, control unit and the arithmetic and logic unit Course Requirement

Week1 (Second Hour)


Definition of sequential program
A Computer is a device or set of devices that work under the control of a stored
program, automatically accepts and processes data to provide information.
 Automatic: it carries out instructions with minimum human intervention
 Re-programmable: it stores instruction (the program)
 A data processor: it carries out operations on data (numbers or words) made up of a
combination of digits to produce information.
Data is the name given to facts. Information is the meaningful data that is relevant, accurate, up
to date and can be used to make decisions.

All programs are sequential in that they execute a sequence of instructions in a pre-defined
order: Sequential programs. There is a single thread of execution or control. ... A concurrent
program is one consisting of two or more processes — threads of execution or control. Each
process is itself a sequential program.
A sequential algorithm or serial algorithm is an algorithm that is executed sequentially – once
through, from start to finish, without other processing executing – as opposed to concurrently or
in parallel.

1
Categorize different programming Languages

Different languages have different purposes, so it makes sense to talk about different kinds, or
types, of languages. Some types are:

 Machine languages, that are interpreted directly in hardware


 Assembly languages, that are thin wrappers over a corresponding machine language
 High-level languages, that are anything machine-independent
 System languages, that are designed for writing low-level tasks, like memory and
process management
 Scripting languages, that are generally extremely high-level and powerful
 Domain-specific languages, that are used in highly special-purpose areas only
 Visual languages, that are non-text based

Machine Code

Most computers work by executing stored programs in a fetch-execute cycle. Machine code
generally features

 Registers to store values and intermediate results


 Very low-level machine instructions (add, sub, div, sqrt)
 Labels and conditional jumps to express control flow
 A lack of memory management support — programmers do that themselves

Machine code is usually written in hex. Example for the Intel 64 architecture:

89 F8 A9 01 00 00 00 75 06 6B C0 03 FF C0 C3 C1 E0 02 83 E8 03 C3

Assembly Language

An assembly language is basically just a simplistic encoding of machine code into something
more readable. It does add labeled storage locations and jump targets and subroutine starting
addresses, but not much more. Here’s the function on the Intel 64 architecture using the GAS
assembly language:

High-Level Languages

A high-level language gets away from all the constraints of a particular machine. HLLs have
features such as:

 Names for almost everything: variables, types, subroutines, constants, modules


 Complex expressions (e.g. 2 * (y^5) >= 88 && sqrt(4.8) / 2 % 3 == 9)
 Control structures (conditionals, switches, loops)
 Composite types (arrays, structs)
 Type declarations
 Type checking

2
 Easy ways to manage global, local and heap storage
 Subroutines with their own private scope
 Abstract data types, modules, packages, classes
 Exceptions

System Languages

System programming languages differ from application programming languages in that they are
more concerned with managing a computer system rather than solving general problems in
health care, game playing, or finance. System languages deal with:

 Memory management
 Process management
 Data transfer
 Caches
 Device drivers
 Operating systems

Scripting Languages

Scripting languages are used for wiring together systems and applications at a very high level.
They are almost always extremely expressive (they do a lot with very little code) and usually
dynamic (the compiler does little, the run-time system does almost everything).

Definition - What does Low-Level Language mean?

Low-level language is a programming language that deals with a computer's hardware


components and constraints. It has no or a minute level of abstraction in reference to a computer
and works to manage a computer's operational semantics.

Low-level language may also be referred to as a computer’s native language.

The term low level means closeness to the way in which the machine has been built. Low level
languages are machine oriented and require extensive knowledge of computer hardware and its
configuration. Low level language is further divided into -

a. Machine Language.
b. Assembly Language.

(a) Machine Language:


Machine Language is the only language that is directly understood by the computer. It does not
needs any translator program. We also call it machine code and it is written as strings of 1's (one)
and 0’s (zero). When this sequence of codes is fed to the computer, it recognizes the codes and
converts it in to electrical signals needed to run it. For example, a program instruction may look
like this:

3
1011000111101

It is not an easy language for you to learn because of its difficult to understand. It is efficient for
the computer but very inefficient for programmers. It is considered to the first generation
language. It is also difficult to debug the program written in this language.

Advantage Machine Language:


The only advantage is that program of machine language run very fast because no translation
program is required for the CPU.

Disadvantages Machine Language:


1. It is very difficult to program in machine language. The programmer has to know details of
hardware to write program.
2. The programmer has to remember a lot of codes to write a program which results in program
errors.
3. It is difficult to debug the program.

(b) Assembly Language:


It is the first step to improve the programming structure. You should know that computer can
handle numbers and letter. Therefore some combination of letters can be used to substitute for
number of machine codes.
The set of symbols and letters forms the Assembly Language and a translator program is
required to translate the Assembly Language to machine language. This translator program is
called `Assembler'. It is considered to be a second-generation language.

Advantages Assembly Language:


1.The symbolic programming of Assembly Language is easier to understand and saves a lot of
time and effort of the programmer.
2. It is easier to correct errors and modify program instructions.
3 .Assembly Language has the same efficiency of execution as the machine level language.
Because this is one-to-one translator between assembly language program and its corresponding
machine language program.

Disadvantages Assembly Language:


1.One of the major disadvantages is that assembly language is machine dependent. A program
written for one computer might not run in other computers with different hardware configuration.

4
Declarative And Imperative (Procedural)Languages

Imperative programming is a programming paradigm that uses statements that change a


program's state. In much the same way that the imperative mood in natural languages expresses
commands, an imperative program consists of commands for the computer to perform.
Imperative programming focuses on describing how a program operates.

The term is often used in contrast to declarative programming, which focuses on what the
program should accomplish without specifying how the program should achieve the result.

Procedural programming is a type of imperative programming in which the program is built from
one or more procedures (also termed subroutines or functions). The terms are often used as
synonyms, but the use of procedures has a dramatic effect on how imperative programs appear
and how they are constructed. Heavily-procedural programming, in which state changes are
localized to procedures or restricted to explicit arguments and returns from procedures, is a form
of structured programming. From the 1960s onwards, structured programming and modular
programming in general have been promoted as techniques to improve the maintainability and
overall quality of imperative programs. The concepts behind object-oriented programming
attempt to extend this approach. E,g FORTRAN,COBOL,FORTRAN

Procedural programming could be considered a step towards declarative programming. A


programmer can often tell, simply by looking at the names, arguments, and return types of
procedures (and related comments), what a particular procedure is supposed to do, without
necessarily looking at the details of how it achieves its result. At the same time, a complete
program is still imperative since it fixes the statements to be executed and their order of
execution to a large extent.

Declarative programming is a programming paradigm—a style of building the structure and


elements of computer programs—that expresses the logic of a computation without describing its
control flow.

Many languages that apply this style attempt to minimize or eliminate side effects by describing
what the program must accomplish in terms of the problem domain, rather than describe how to
accomplish it as a sequence of the programming language primitives[2] (the how being left up to
the language's implementation). This is in contrast with imperative programming, which
implements algorithms in explicit steps.

Declarative programming often considers programs as theories of a formal logic, and


computations as deductions in that logic space. Declarative programming may greatly simplify
writing parallel programs.

Common declarative languages include those of database query languages (e.g., SQL, XQuery),
regular expressions, logic programming, functional programming, and configuration
management systems.

5
Declarative programming is often defined as any style of programming that is not imperative. A
number of other common definitions exist that attempt to give the term a definition other than
simply contrasting it with imperative programming. For example:

 A program that describes what computation should be performed and not how to compute
it
 Any programming language that lacks side effects (or more specifically, is referentially
transparent)
 A language with a clear correspondence to mathematical logic.[4]

These definitions overlap substantially.

Declarative programming contrasts with imperative and procedural programming. Declarative


programming is a non-imperative style of programming in which programs describe their desired
results without explicitly listing commands or steps that must be performed. Functional and
logical programming languages are characterized by a declarative programming style. In logical
programming languages, programs consist of logical statements, and the program executes by
searching for proofs of the statements.

In a pure functional language, such as Haskell, all functions are without side effects, and state
changes are only represented as functions that transform the state, which is explicitly represented
as a first class object in the program. Although pure functional languages are non-imperative,
they often provide a facility for describing the effect of a function as a series of steps. Other
functional languages, such as Lisp, OCaml and Erlang, support a mixture of procedural and
functional programming.

Some logical programming languages, such as Prolog, and database query languages, such as
SQL, while declarative in principle, also support a procedural style of programming.

In broad terms there are declarative languages and the rest. The rest are generally imperative or
procedural. Declarative languages are generally cleaner, more clearly specified, and more
powerful once you get familiar with them but in many cases (such as Haskell) a bit trickier to
pick up initially for most people. Declarative languages tend to be more abstract. Imperative or
procedural languages (like C) leave more chores for the programmer and give the computer less
opportunity to pitch in during compilation, interpretation, or optimization phases.

A good metaphor for declarative languages is a set of true statements about something. The
combination of all the true statements gives the computer enough hints to do what you wanted
without telling it exactly what to do in a precise order. This is like a math or logic book. In
general declarative languages are more powerful for parallel or distributed processing. An
imperative language is more like a sequence of steps such as a recipe. Another example of an
imperative language might be a script for a screenplay or theater production. An imperative
language is basically a sequence of commands that say "do this, then do that!" in great detail
with many small steps.

6
Definition of Computer language

A language is a system of communication. Humans communicate with one another in some


language, like English, German or in many other languages. We, humans, can also communicate
through gestures, facial expressions, even through our emotions we can express our selves and
our feelings. In order to make computers work for us, some sort of instructions must be stored in
a some kind of language. And that language is called a Programming Language. A programming
language consists of all the symbols, characters, and usage rules that permit people to
communicate with computers. There are at least several hundred, and possibly several thousand
different programming languages. Some of these are created to serve a special purpose
(controlling a robot), while others are more flexible general-purpose tools that are suitable for
many types of applications.

What is a Programming Language?

A programming language is a set of written symbols that instructs the computer hardware to
perform specific tasks. Typically, a programming language consists of a vocabulary and a set of
rules (called syntax) that the programmer must learn".

1st generation of programming languages

Machine language is the only programming language that the computer can understand directly
without translation. It is a language made up of entirely 1s and 0s. There is not, however, one
universal machine language because the language must be written in accordance with the special
characteristics of a given processor. Each type or family of processor requires its own machine
language. For this reason, machine language is said to be machine-dependent (also called
hardware-dependent).

In the computer’s first generation, programmers had to use machine language because no other
option was available. Machine language programs have the advantage of very fast execution
speeds and efficient use of primary memory. Use of machine language is very tedious, difficult
and time consuming method of programming. Machine language is low-level language. Since the
programmer must specify every detail of an operation, a low-level language requires that the
programmer have detailed knowledge of how the computer works. Programmers had to know a
great deal about the computer’s design and how it functioned. As a result, programmers were
few in numbers and lacked complexity. To make programming simpler, other easier-to-use
programming languages have been developed. These languages, however must ultimately be
translated into machine language before the computer can understand and use them.

2nd Generation of programming languages

The first step in making software development easier and more efficient was the creation of
Assembly languages. They are also classified as low-level languages because detailed
knowledge of hardware is still required. They were developed in 1950s. Assembly languages use
mnemonic operation codes and symbolic addresses in place of 1s and 0s to represent the
operation codes. A mnemonic is an alphabetical abbreviation used as memory aid. This means a

7
programmer can use abbreviation instead of having to remember lengthy binary instruction
codes. For example, it is much easier to remember L for Load, A for Add, B for Branch, and C
for Compare than the binary equivalents i-e different combinations of 0s and 1s.

Assembly language uses symbolic addressing capabilities that simplify the programming process
because the programmer does not need to know or remember the exact storage locations of
instructions or data. Symbolic addressing is the ability to express an address in terms of symbols
chosen by the programmer rather than in terms of the absolute numerical location. Therefore, it
is not necessary to assign and remember a number that identifies the address of a piece of data.

Although assembly languages represented an improvement, they had obvious limitations. Only
computer specialists familiar with the architecture of the computer being used can use them. And
because they are also machine dependent, assembly languages are not easily converted to run on
other types of computers.

Before they can be used by the computer, assembly languages must be translated into machine
language. A language translator program called an assembler does this conversion. Assembly
languages provide an easier and more efficient way to program than machine languages while
still maintaining control over the internal functions of a computer at the most basic level. The
advantages of programming with assembly languages are that they produce programs that are
efficient, use less storage, and execute much faster than programs designed using high-level
languages.

3rd Generation of programming languages

Third generation languages, also known as high-level languages, are very much like everyday
text and mathematical formulas in appearance. They are designed to run on a number of different
computers with few or no changes.

Objectives of high-level languages

 To relieve the programmer of the detailed and tedious task of writing programs in
machine language and assembly languages.
 To provide programs that can be used on more than one type of machine with very few
changes.
 To allow the programmer more time to focus on understanding the user’s needs and
designing the software required meeting those needs.

Most high level languages are considered to be procedure-oriented, or Procedural languages,


because the program instructions comprise lists of steps, procedures, that tell the computer not
only what to do but how to do it. High-level language statements generate, when translated, a
comparatively greater number of assembly language instructions and even more machine
language instructions. The programmer spends less time developing software with a high level
language than with assembly or machine language because fewer instructions have to be created.

8
A language translator is required to convert a high-level language program into machine
language. Two types of language translators are used with high level languages: compilers and
interpreters.

4th Generation of programming languages

Fourth generation languages are also known as very high level languages. They are non-
procedural languages, so named because they allow programmers and users to specify what the
computer is supposed to do without having to specify how the computer is supposed to do it.
Consequently, fourth generation languages need approximately one tenth the number of
statements that a high level languages needs to achieve the same results. Because they are so
much easier to use than third generation languages, fourth generation languages allow users, or
non-computer professionals, to develop software.

Objectives of fourth generation languages

 Increasing the speed of developing programs.


 Minimizing user effort to obtain information from computer.
 Decreasing the skill level required of users so that they can concentrate on the application
rather than the intricacies of coding, and thus solve their own problems without the aid of
a professional programmer.

 Minimizing maintenance by reducing errors and making programs that are easy to
change.

Depending on the language, the sophistication of fourth generation languages varies widely.
These languages are usually used in conjunction with a database and its data dictionary.

Five basic types of language tools fall into the fourth generation language category.

1. Query languages
2. Report generators.
3. Applications generators.
4. Decision support systems and financial planning languages.
5. Some microcomputer application software.

Query languages

Query languages allow the user to ask questions about, or retrieve information from database
files by forming requests in normal human language statements (such as English). The difference
between the definitions for query language and for database management systems software is so
slight that most people consider the definitions to be the same. Query languages do have a
specific grammar vocabulary, and syntax that must be mastered, but this is usually a simple task
for both users and programmers.

9
Application generators

Application generators allow the user to reduce the time it takes to design an entire software
application that accepts input, ensures data has been input accurately, performs complex
calculations and processing logic, and outputs information in the form of reports. The user must
key into computer-useable form the specification for what the program is supposed to do. The
resulting file is input to the applications generator, which determine how to perform the tasks and
which then produces the necessary instructions for the software program.

Decision support systems and financial planning languages combine special interactive computer
programs and some special hardware to allow high level managers to bring data and information
together from different sources and manipulate it in new ways.

Some microcomputer applications software can also be used to create specialized applications –
in other words, to create new software. Microcomputer software packages that fall into this
category include many spreadsheet programs (such as Lotus 1-2-3), database managers (Such as
dBase IV), and integrated packages (such as Symphony).

Programming Language base on implementation: High Level Language (HLL)

A programming language implementation is a system for executing computer programs.

There are two general approaches to programming language implementation:

 Interpretation: An interpreter takes as input a program in some language, and performs


the actions written in that language on some machine.
 Compilation: A compiler takes as input a program in some language, and translates that
program into some other language, which may serve as input to another interpreter or
another compiler.

Notice that a compiler does not directly execute the program. Ultimately, in order to execute a
program via compilation, it must be translated into a form that can serve as input to an
interpreter.

When a piece of computer hardware can interpret a programming language directly, that
language is called machine code. A so-called native code compiler is one that compiles a
program into machine code. Actual compilation is often separated into multiple passes, like code
generation (often for assembler language), translator (generating native code), linking, loading
and execution.

If a compiler of a given high level language produces another high level language, it is called
translator (source to source translation), which is often useful to add extensions to existing
languages or to exploit good and portable implementation of other language (for example C),
simplifying development.

10
Imperative and Declarative Programming Language
In computer science, a high-level programming language is a programming language with
strong abstraction from the details of the computer. In comparison to low-level programming
languages, it may use natural language elements, be easier to use, or may automate (or even hide
entirely) significant areas of computing systems (e.g. memory management), making the process
of developing a program simpler and more understandable relative to a lower-level language.
The amount of abstraction provided defines how "high-level" a programming language is.

Features

"High-level language" refers to the higher level of abstraction from machine language. Rather
than dealing with registers, memory addresses and call stacks, high-level languages deal with
variables, arrays, objects, complex arithmetic or boolean expressions, subroutines and functions,
loops, threads, locks, and other abstract computer science concepts, with a focus on usability
over optimal program efficiency. Unlike low-level assembly languages, high-level languages
have few, if any, language elements that translate directly into a machine's native opcodes. Other
features, such as string handling routines, object-oriented language features, and file
input/output, may also be present.

Execution modes

There are three general modes of execution for modern high-level languages:

Interpreted
When code written in a language is interpreted, its syntax is read and then executed
directly, with no compilation stage. A program called an interpreter reads each program
statement, following the program flow, then decides what to do, and does it. A hybrid of
an interpreter and a compiler will compile the statement into machine code and execute
that; the machine code is then discarded, to be interpreted anew if the line is executed
again. Interpreters are commonly the simplest implementations of the behavior of a
language, compared to the other two variants listed here.
Compiled
When code written in a language is compiled, its syntax is transformed into an executable
form before running. There are two types of compilation:
Machine code generation
Some compilers compile source code directly into machine code. This is the original
mode of compilation, and languages that are directly and completely transformed to
machine-native code in this way may be called "truly compiled" languages. See assembly
language.
Intermediate representations
When code written in a language is compiled to an intermediate representation, that
representation can be optimized or saved for later execution without the need to re-read
the source file. When the intermediate representation is saved, it may be in a form such as
byte code. The intermediate representation must then be interpreted or further compiled
to execute it. Virtual machines that execute byte code directly or transform it further into

11
machine code have blurred the once clear distinction between intermediate
representations and truly compiled languages.
Source-to-Source Translated or Trans-compiled
Code written in a language may be translated into terms of a lower-level programming
language for which native code compilers are already widely available. JavaScript and
the C programming language are common targets for such translators. See CoffeeScript,
Chicken Scheme, and Eiffel as examples. Specifically, the generated C and C++ code can
be seen (as generated from the Eiffel programming language when using the EiffelStudio
IDE) in the EIFGENs directory of any compiled Eiffel project. In Eiffel, the "Translated"
process is referred to as Trans-compiling or Trans-compiled, and the Eiffel compiler as a
Transcompiler.

Note that languages are not strictly "interpreted" languages or "compiled" languages. Rather,
implementations of language behavior use interpretation or compilation. For example, Algol 60
and Fortran have both been interpreted (even though they were more typically compiled).
Similarly, Java shows the difficulty of trying to apply these labels to languages, rather than to
implementations; Java is compiled to bytecode and the bytecode is subsequently executed by
either interpretation (in a JVM) or compilation (typically with a just-in-time compiler such as
HotSpot, again in a JVM). Moreover, compilation, trans-compiling, and interpretation are not
strictly limited to just a description of the compiler artifact (binary executable or IL assembly).

Low level languages

A low-level programming language is a programming language that provides little or no


abstraction from a computer's instruction set architecture—commands or functions in the
language map closely to processor instructions. Generally this refers to either machine code or
assembly language. The word "low" refers to the small or nonexistent amount of abstraction
between the language and machine language; because of this, low-level languages are sometimes
described as being "close to the hardware". Programs written in low-level languages tend to be
relatively non-portable, mainly because of the close relationship between the language and the
hardware architecture.

Low-level languages can convert to machine code without a compiler or interpreter— second-
generation programming languages use a simpler processor called an assembler— and the
resulting code runs directly on the processor. A program written in a low-level language can be
made to run very quickly, with a small memory footprint. An equivalent program in a high-level
language can be less efficient and use more memory. Low-level languages are simple, but
considered difficult to use, due to numerous technical details that the programmer must
remember. By comparison, a high-level programming language isolates execution semantics of a
computer architecture from the specification of the program, which simplifies development.

12
Machine code

Machine code is the only language a computer can process directly without a previous
transformation. Currently, programmers almost never write programs directly in machine code,
because it requires attention to numerous details that a high-level language handles
automatically. Furthermore it requires memorizing or looking up numerical codes for every
instruction, and is extremely difficult to modify.

True machine code is a stream of raw, usually binary, data. A programmer coding in "machine
code" normally codes instructions and data in a more readable form such as decimal, octal, or
hexadecimal which is translated to internal format by a program called a loader or toggled into
the computer's memory from a front panel.

Although few programs are written in machine language, programmers often become adept at
reading it through working with core dumps or debugging from the front panel.

Example: A function in hexadecimal representation of 32-bit x86 machine code to calculate the
nth Fibonacci number:

8B542408 83FA0077 06B80000 0000C383


FA027706 B8010000 00C353BB 01000000
B9010000 008D0419 83FA0376 078BD989
C14AEBF1 5BC3

Assembly

Second-generation languages provide one abstraction level on top of the machine code. In the
early days of coding on computers like the TX-0 and PDP-1, the first thing MIT hackers did was
write assemblers. Assembly language has little semantics or formal specification, being only a
mapping of human-readable symbols, including symbolic addresses, to opcodes, addresses,
numeric constants, strings and so on. Typically, one machine instruction is represented as one
line of assembly code. Assemblers produce object files that can link with other object files or be
loaded on their own.

Most assemblers provide macros to generate common sequences of instructions.

Example: The same Fibonacci number calculator as above, but in x86 assembly language using
MASM syntax:

13
fib:
mov edx, [esp+8]
cmp edx, 0
ja @f
mov eax, 0
ret

@@:
cmp edx, 2
ja @f
mov eax, 1
ret

@@:
push ebx
mov ebx, 1
mov ecx, 1

@@:
lea eax, [ebx+ecx]
cmp edx, 3
jbe @f
mov ebx, ecx
mov ecx, eax
dec edx
jmp @b

@@:
pop ebx
ret

In this code example, hardware features of the x86 processor (its registers) are named and
manipulated directly. The function loads its input from a precise location in the stack (8 bytes
higher than the location stored in the ESP stack pointer) and performs its calculation by
manipulating values in the EAX, EBX, ECX and EDX registers until it has finished and returns.
Note that in this assembly language, there is no concept of returning a value. The result having
been stored in the EAX register, the RET command simply moves code processing to the code
location stored on the stack (usually the instruction immediately after the one that called this
function) and it is up to the author of the calling code to know that this function stores its result
in EAX and to retrieve it from there. x86 assembly language imposes no standard for returning
values from a function (and so, in fact, has no concept of a function); it is up to the calling code
to examine state after the procedure returns if it needs to extract a value.

14
Basic computer architecture

Digital systems are designed to store, process, and communicate information in digital form.
They are found in a wide range of applications, including process control, communication
systems, digital instruments, and consumer products. A digital computer, more commonly called
simply a computer, is an example of a typical digital system.

A computer manipulates information in digital or more precisely, binary form. A binary number
has only two discrete values: zero or one. Each discrete value is represented by the OFF and ON
status of an electronic switch called a transistor. All computers understand only binary numbers.
Any decimal number (base 10, with ten digits from 0 to 9) can be represented by a binary
number (base 2, with digits 0 and 1).

The basic blocks of a computer are the central processing unit (CPU), the memory, and the
input/output (I/O). The CPU of a computer is basically the same as the brain of a human being;
so computer memory is conceptually similar to human memory. A question asked of a human
being is analogous to entering a program into a computer using an input device such as a
keyboard, and a person answering a question is similar in concept to outputting the program
result to a computer output device such as a printer. The main difference is that human beings
can think independently, whereas computers can only answer questions for which they are
programmed. Computer hardware includes such components as memory, CPU, transistors, ...

A computer accepts and then processes input data according to the instructions it is given. The

elements of any sort of processing are INPUT, PROCESSING, STORAGE, and OUTPUT that

can be depicted as shown in the following diagram.

A Computer operations are performed according to programmed logical and arithmetical rules.

The arithmetical element might be as simple as x + y = z. The logic will be something along the

lines of if x + y does not equal z then add 3 to x and try again.

Microcomputer Organization:

The basic components of a microcomputer are:

1) CPU

2) Program memory

15
3) Data memory

4) Output ports

5) Input ports

6) Clock generator.

These components are shown in figure below:

Central Processing Unit:

The CPU consists of ALU (Arithmetic and Logic Unit), Register unit and control unit. The CPU
retrieves stored instructions and data word from memory; it also deposits processed data in
memory.

a) ALU (Arithmetic and Logic Unit) This section performs computing functions on data. These

functions are arithmetic operations such as additions subtraction and logical operation such as
AND, OR rotate etc. Result are stored either in registers or in memory orsent to output devices.

b) Register Unit:

It contains various register. The registers are used primarily to store data temporarily during the
execution of a program. Some of the registers are accessible to the uses through instructions.

c) Control Unit:

It provides necessary timing & control signals necessary to all the operations in the
microcomputer. It controls the flow of data between the p and peripherals (input, output &
memory). The control unit gets a clock which determines the speed of the p.

The CPU has three basic functions

1) It fetches an instructions word stored in memory.

2) It determines what the instruction is telling it to do.(decodes the instruction)

3) It executes the instruction. Executing the instruction may include same of the following major
tasks.

1. Transfer of data from reg. toreg. in the CPU itself.

2. Transfer of data between a CPU reg. & specified memory location.

16
3. Performing arithmetic and logical operations on data from a specific memory location or a
designated CPU register.

4. Directing the CPU to change a sequence of fetching instruction, if processing the data created
a specific condition.

5. Performing housekeeping function within the CPU itself in order to establish desired condition
at certain registers.

4) It looks for control signal such as interrupts and provides appropriate responses.

5) It provides states, control, and timing signals that the memory and input/output section can
use.

Program Memory:

The basic task of a microcomputer system into ensure that its CPU executes the desired
instruction sequence is the program properly. The instruction sequence isstared in the program
memory on initialization- usually a power up and manual reset the processor starts by executing
the instruction in a predetermined location in program memory. The first instruction of the
program should therefore be in this location in typical µp basic system, the program to

be executed is fixed one which does not change. Therefore µp program are store on ROM, or
PROM, EPROM, EEPROM.

In the trainer kit, ROM contains only the monitor program. The user program is not stored in
ROM because it needs not to be stored permanently.

Data Memory:

A microcomputer manipulates data according to the algorithm given by the instruction in the
program in the program memory. These instruction may require intermediate results to be stored,
the functional block in µc have same internal reg. which can also be used if available for such
storage external data memory is needed if the storage requirements is more.

Apart from intermediate storage, the data memory may also be used to provide data needed by
the program, to store some of the results of the program. Data memoryis used for all storage
purposes other than storage of program. Therefore, they must have head write capability RWM
or RAM.

It stores both the instructions to be executed (i.e. program) and the data involved. It usually
contains ROM (Read memory). The ROM can only read and cannot be written intoand is non
volatile that is, it retains its contents when the power is turned off. A ROM is typically used to
store instructions and data that do not change.For example, it stores the monitor program if a
microcomputer.

17
One can either read from or write into a RWM. The RWM is volatile, that is it does not retainits
contents when the power is turned off. It is used to store user programmes & data which are
temporary might change during the course ofexecuting a program. Both ROM & RWM are
RAM (Random access memory). RWM is respectively.

During a memory read operation, the content of the addressed location is not destroyed. During a
unit operation, the original content of the addressed location is destroyed.

Both ROM & RWM are arranged into words, each of which has a unique address. The address of
a word is memory location and it is placed in parentheses. Therefore, Xis an address and (X) is
the content of that address X.

The address decodes taken an address and from the control unit and select the proper memory
location and obtaining its content takes a certain amount of time, this times is the access time of
the memory. The access time affects the speed of the computer, pins, and the computer must
obtain the instruction and data from the memory. Computer memory as usually RAM so that all
memory location have the same access time. The computer must wait shiner of unit’s memory,
typical memoryaccess time range from several uses.

Memory sections often subdivided into units called pages. The entire memory section may
involve million of cords, when a page contains between 256 & 4k warts. The computer may
access a memory location by first decreasing a particular page and then accessing a location on
that page. The advantage of paging is that the computer can reach several locations on the same
page with just the address in the page. The process is like describing street address by first
specifying aspect and them listing the have numbers.

The control section transfers data toor from memory as follows.

1. The control section reads an address to the memory.

2. The control section sends a read and write signal to the memory to indicate, the direction of
the transform.

3. The control section waits until transfer has been completed .this delay precedes the actual
data’s transfer in the input case and follows it in the output case.

Input / Output Ports:

The input & output ports provide the microcomputer the capability to communicate with the
outside world. The input ports allow data to pass from the outside world to the µc data which
will be used in the data manipulation being done by the microcomputer to send data to output
devices The user can enter instruction (i.e. program) and data in memory through input devices
such as keyboard, or simple switches, CRT, disk devices, tape or card readers. Computers are
also used to measure and control physical quantities like temperature, pressure, speed etc. For
these purposes, transducers are used to convent physical quantise into proportional electrical
signals A/D computers are used to convert electrical signals into digital signals which are sent to

18
the compute. The computer sends the results of the computation to the output devices e.g. LED,
CRT, D/A converters, printers etc.. These I/O devices allow the computer to communicate with
the outside world I/O devices are called peripherals.

Clock Generator:

Operations inside the p as well as in other parts of the c, are usually synchronous by nature.The
clock generator generates the appropriate clock periods during which instruction executions are
carried out by the microprocessor. This condition ensures that events in different path of the
systems can proceed in a systematic fashion. Some of the microprocessors have an internal clock
generator circuit to generate a clock signal. These microprocessors require an external crystal or
RC networkto be connected at the appropriate pins for deciding the operating frequency (e.g.
8085). Some microprocessors require an external clock generator (e.g. 8086).These
microprocessors also provides an output clock signal which can be used by other devicesin the
microcomputer system for their can timing and synchronizing.

A processor register (CPU register) is one of a small set of data holding places that are part of the
computer processor.

A register may hold an instruction, a storage address, or any kind of data (such as a bit sequence
or individual characters). Some instructions specify registers as part of the instruction. For
example, an instruction may specify that the contents of two defined registers be added together
and then placed in a specified register.

A register must be large enough to hold an instruction - for example, in a 64-bit computer, a
register must be 64 bits in length. In some computer designs, there are smaller registers - for
example, half-registers - for shorter instructions. Depending on the processor design and
language rules, registers may be numbered or have arbitrary names.

A processor typically contains multiple index registers, also known as address registers or
registers of modification. The effective address of any entity in a computer includes the base,
index, and relative addresses, all of which are stored in the index register. A shift register is
another type. Bits enter the shift register at one end and emerge from the other end. Flip flops,
also known as bistable gates, store and process the data.

CPU Registers

In computer architecture, a processor register is a very fast computer memory used to speed the
execution of computer programs by providing quick access to commonly used values-typically,
the values being in the midst of a calculation at a given point in time.

These registers are the top of the memory hierarchy, and are the fastest way for the system to
manipulate data. In a very simple microprocessor, it consists of a single memory location,
usually called an accumulator. Registers are built from fast multi-ported memory cell. They
19
must be able to drive its data onto an internal bus in a single clock cycle. The result of ALU
operation is stored here and could be re-used in a subsequent operation or saved into memory.

Registers are normally measured by the number of bits they can hold, for example, an “8-bit
register” or a “32-bit register”. Registers are now usually implemented as a register file, but they
have also been implemented using individual flip-flops, high speed core memory, thin film
memory, and other ways in various machines.

CPU Register

The term is often used to refer only to the group of registers that can be directly indexed for input
or output of an instruction, as defined by the instruction set. More properly, these are called the
“architected registers“. For instance, the x86 instruction set defines a set of eight 32-bit registers,
but a CPU that implements the X86 instruction set will contain many more hardware registers
than just these eight.

There are several other classes of registers:

(a) Accumulator: It is most frequently used register used to store data taken from memory. Its
number varies from microprocessor to microprocessor.

(b) General Purpose registers: General purpose registers are used to store data and intermediate
results during program execution. Its contents can be accessed through assembly programming.

(c) Special purpose Registers: Users do not access these registers. These are used by computer
system at the time of program execution. Some types of special purpose registers are given
below:

 Memory Address Register (MAR): It stores address of data or instructions to be fetched


from memory.
 Memory Buffer Register (MBR): It stores instruction and data received from the
memory and sent from the memory.
 Instruction Register (IR): Instructions are stored in instruction register. When one
instruction is completed, next instruction is fetched in memory for processing.
 Program Counter (PC): It counts instructions.

20
The instruction cycle is completed into two phases: (a) Fetch Cycle and (b) Execute Cycle.
There are two parts in instruction- opcode and operand. In fetch cycle opcode of instruction is
fetched into CPU. The opcode, at first, is reached to Data Register (DR), then to Instruction
Register (IR). Decoder accesses the opcode and it decodes opcode and type of operation is
declared to CPU and execution cycle is started.

Registers are the most important components of CPU. Each register performs a specific function.
A brief description of most important CPU's registers and their functions are given below:

1. Memory Address Register (MAR):

This register holds the address of memory where CPU wants to read or write data. When CPU
wants to store some data in the memory or reads the data from the memory, it places the address
of the required memory location in the MAR.

2. Memory Buffer Register (MBR):

This register holds the contents of data or instruction read from, or written in memory. The
contents of instruction placed in this register are transferred to the Instruction Register, while the
contents of data are transferred to the accumulator or I/O register.

In other words you can say that this register is used to store data/instruction coming from the
memory or going to the memory.

3. I/O Address Register (I/O AR):


I/O Address register is used to specify the address of a particular I/O device.

4. I/O Buffer Register (I/O I3R):

I/O Buffer Register is used for exchanging data between the I/O module and the processor.

5. Program Counter (PC)

Program Counter register is also known as Instruction Pointer Register. This register is used to
store the address of the next instruction to be fetched for execution. When the instruction is
fetched, the value of IP is incremented. Thus this register always points or holds the address of
next instruction to be fetched.

6. Instruction Register (IR):

Once an instruction is fetched from main memory, it is stored in the Instruction Register. The
control unit takes instruction from this register, decodes and executes it by sending signals to the
appropriate component of computer to carry out the task.

21
7. Accumulator Register:

The accumulator register is located inside the ALU, It is used during arithmetic & logical
operations of ALU. The control unit stores data values fetched from main memory in the
accumulator for arithmetic or logical operation. This register holds the initial data to be operated
upon, the intermediate results, and the final result of operation. The final result is transferred to
main memory through MBR.

8. Stack Control Register:

A stack represents a set of memory blocks; the data is stored in and retrieved from these blocks
in an order, i.e. First In and Last Out (FILO). The Stack Control Register is used to manage the
stacks in memory. The size of this register is 2 or 4 bytes.

9. Flag Register:

The Flag register is used to indicate occurrence of a certain condition during an operation of the
CPU. It is a special purpose register with size one byte or two bytes. Each bit of the flag register
constitutes a flag (or alarm), such that the bit value indicates if a specified condition was
encountered while executing an instruction.

For example, if zero value is put into an arithmetic register (accumulator) as a result of an
arithmetic operation or a comparison, then the zero flag will be raised by the CPU. Thus, the
subsequent instruction can check this flag and when a zero flag is "ON" it can take, an
appropriate route in the algorithm.

Assembly language

An assembly (or assembler) language, often abbreviated asm, is a low-level programming


language for a computer, or other programmable device, in which there is a very strong
(generally one-to-one) correspondence between the language and the architecture's machine code
instructions. Each assembly language is specific to a particular computer architecture. In
contrast, most high-level programming languages are generally portable across multiple
architectures but require interpreting or compiling. Assembly language may also be called
symbolic machine code. Assembly language is converted into executable machine code by a
utility program referred to as an assembler. The conversion process is referred to as assembly, or
assembling the source code. Assembly time is the computational step where an assembler is
run.Assembly language uses a mnemonic to represent each low-level machine instruction or
opcode, typically also each architectural register, flag, etc. Many operations require one or more
operands in order to form a complete instruction and most assemblers can take expressions of
numbers and named constants as well as registers and labels as operands, freeing the
programmer from tedious repetitive calculations. Depending on the architecture, these elements
22
may also be combined for specific instructions or addressing modes using offsets or other data as
well as fixed addresses. Many assemblers offer additional mechanisms to facilitate program
development, to control the assembly process, and to aid debugging

For example, the instruction below tells an x86/IA-32 processor to move an immediate 8-bit
value into a register. The binary code for this instruction is 10110 followed by a 3-bit identifier
for which register to use. The identifier for the AL register is 000, so the following machine code
loads the AL register with the data 01100001.

10110000 01100001

This binary computer code can be made more human-readable by expressing it in hexadecimal as
follows.

B0 61

Here, B0 means 'Move a copy of the following value into AL', and 61 is a hexadecimal
representation of the value 01100001, which is 97 in decimal. Assembly language for the 8086
family provides the mnemonic MOV (an abbreviation of move) for instructions such as this, so
the machine code above can be written as follows in assembly language, complete with an
explanatory comment if required, after the semicolon. This is much easier to read and to
remember.

MOV AL, 61h ; Load AL with 97 decimal (61 hex)

In some assembly languages the same mnemonic such as MOV may be used for a family of
related instructions for loading, copying and moving data, whether these are immediate values,
values in registers, or memory locations pointed to by values in registers. Other assemblers may
use separate opcode mnemonics such as L for "move memory to register", ST for "move register
to memory", LR for "move register to register", MVI for "move immediate operand to memory",
etc.

The x86 opcode 10110000 (B0) copies an 8-bit value into the AL register, while 10110001 (B1)
moves it into CL and 10110010 (B2) does so into DL. Assembly language examples for these
follow.[8]

MOV AL, 1h ; Load AL with immediate value 1


MOV CL, 2h ; Load CL with immediate value 2
MOV DL, 3h ; Load DL with immediate value 3

The syntax of MOV can also be more complex as the following examples show.[9]

MOV EAX, [EBX] ; Move the 4 bytes in memory at the address contained in EBX into
EAX
MOV [ESI+EAX], CL ; Move the contents of CL into the byte at address ESI+EAX

23
In each case, the MOV mnemonic is translated directly into an opcode in the ranges 88-8E, A0-
A3, B0-B8, C6 or C7 by an assembler, and the programmer does not have to know or remember
which.

Transforming assembly language into machine code is the job of an assembler, and the reverse
can at least partially be achieved by a disassembler. Unlike high-level languages, there is usually
a one-to-one correspondence between simple assembly statements and machine language
instructions. However, in some cases, an assembler may provide pseudoinstructions (essentially
macros) which expand into several machine language instructions to provide commonly needed
functionality. For example, for a machine that lacks a "branch if greater or equal" instruction, an
assembler may provide a pseudoinstruction that expands to the machine's "set if less than" and
"branch if zero (on the result of the set instruction)". Most full-featured assemblers also provide a
rich macro language (discussed below) which is used by vendors and programmers to generate
more complex code and data sequences.

Each computer architecture has its own machine language. Computers differ in the number and
type of operations they support, in the different sizes and numbers of registers, and in the
representations of data in storage. While most general-purpose computers are able to carry out
essentially the same functionality, the ways they do so differ; the corresponding assembly
languages reflect these differences.

Multiple sets of mnemonics or assembly-language syntax may exist for a single instruction set,
typically instantiated in different assembler programs. In these cases, the most popular one is
usually that supplied by the manufacturer and used in its documentation.

include \masm32\include\masm32rt.inc ; use the Masm32 library

.code
demomain:
REPEAT 20
switch rv(nrandom, 9) ; generate a number between 0 and 8
mov ecx, 7
case 0
print "case 0"
case ecx ; in contrast to most other programming
languages,
print "case 7" ; the Masm32 switch allows "variable cases"
case 1 .. 3
.if eax==1
print "case 1"
.elseif eax==2
print "case 2"
.else
print "cases 1 to 3: other"
.endif
case 4, 6, 8

24
print "cases 4, 6 or 8"
default
mov ebx, 19 ; print 20 stars
.Repeat
print "*"
dec ebx
.Until Sign? ; loop until the sign flag is set
endsw
print chr$(13, 10)
ENDM
exit
end demomain

Basic elements

There is a large degree of diversity in the way the authors of assemblers categorize statements
and in the nomenclature that they use. In particular, some describe anything other than a machine
mnemonic or extended mnemonic as a pseudo-operation (pseudo-op). A typical assembly
language consists of 3 types of instruction statements that are used to define program operations:

 Opcode mnemonics
 Data definitions
 Assembly directives

Opcode mnemonics and extended mnemonics

Instructions (statements) in assembly language are generally very simple, unlike those in high-
level languages. Generally, a mnemonic is a symbolic name for a single executable machine
language instruction (an opcode), and there is at least one opcode mnemonic defined for each
machine language instruction. Each instruction typically consists of an operation or opcode plus
zero or more operands. Most instructions refer to a single value, or a pair of values.

Operands can be immediate (value coded in the instruction itself), registers specified in the
instruction or implied, or the addresses of data located elsewhere in storage. This is determined
by the underlying processor architecture: the assembler merely reflects how this architecture
works. Extended mnemonics are often used to specify a combination of an opcode with a
specific operand, e.g., the System/360 assemblers use B as an extended mnemonic for BC with a
mask of 15 and NOP ("NO OPeration" – do nothing for one step) for BC with a mask of 0.

Extended mnemonics are often used to support specialized uses of instructions, often for
purposes not obvious from the instruction name. For example, many CPU's do not have an
explicit NOP instruction, but do have instructions that can be used for the purpose. In 8086 CPUs
the instruction xchg ax,ax is used for nop, with nop being a pseudo-opcode to encode the
instruction xchg ax,ax. Some disassemblers recognize this and will decode the xchg ax,ax
instruction as nop. Similarly, IBM assemblers for System/360 and System/370 use the extended

25
mnemonics NOP and NOPR for BC and BCR with zero masks. For the SPARC architecture,
these are known as synthetic instructions.[10]

Data directives

There are instructions used to define data elements to hold data and variables. They define the
type of data, the length and the alignment of data. These instructions can also define whether the
data is available to outside programs (programs assembled separately) or only to the program in
which the data section is defined. Some assemblers classify these as pseudo-ops.

Assembly directives
Assembly directives, also called pseudo-opcodes, pseudo-operations or pseudo-ops, are
commands given to an assembler "directing it to perform operations other than assembling
instructions.". Directives affect how the assembler operates and "may affect the object code, the
symbol table, the listing file, and the values of internal assembler parameters." Sometimes the
term pseudo-opcode is reserved for directives that generate object code, such as those that
generate data
ASSEMBLY LANGUAGE PROGRAMMING

INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMING

Summary: This topic introduces the instruction set, data format, addressing modes, status
flag and assembly language programming.

UNDERSTANDING INSTRUCTION SET AND ASSEMBLY LANGUAGE

Define instruction set, machine and assembly language

INSTRUCTION SET • An instruction set is a list of commands ready to be executed


directly by CPU…

We can simply say that the functions of instruction set is to instruct all CPU's with a set
of instruction that can – tells the CPU where to find data – when to read the data – what
to do with the data Now we will see some of the type of instruction set.

• Data transfer instruction • Arithmetic instruction • Logical instruction and bit


manipulation • Program control instruction • Processing control instruction • Shift and
rotate instruction

1. Machine Language • A machine language sometimes referred to as machine code or


object code. • Machine language is a collection of binary digits or bits that the computer
reads and interprets. • Machine language is the only language a computer is capable of
understanding. • Machine language consists of 0s and 1s.
2. Assembly Language • Is a low-level programming language computers,microprocessors,
microcontrollers and other programmable devices. • Assembly language is just one level
higher than machine language. – Assembly language consists of simple codes. – Each
26
statement in an assembly language corresponds directly to a machine code understood by
the microprocessor. • The software used to convert an assembly program into machines
codes is called an assembler.
3. high Level Programming Low Level Programming
4. Describe features and architectures of various type of microprocessor MOTOROLA 6800
• The Motorola 68000 is a 32-bit CISC microprocessor. • 24 bit address bus • 16 bit data
bus.
5. INTEL 8086 • 8086 has 16-bit ALU; this means 16-bit numbers are directly processed by
8086. • It has 16-bit data bus, so it can read data or write data to memory or I/O ports
either 16 bits or 8 bits at a time. • It has 20 address lines, so it can address up to 220 i.e.
1048576 = 1Mbytes of memory (words i.e. 16 bit numbers are stored in consecutive
memory locations).
6. Describe the Addressing Modes • Many instructions, such as MOV, operates on two
operands. – MOV dest, source • Addressing mode indicates where the operands are
located. • There are various addressing modes in x86. – Register, immediate, direct,
register indirect, base- plus-index, register relative, base relative-plus- index, Register is
a storage element inside a microprocessor.
7. 10. ADDRESSING MODES
8. 11. 1. Register Addressing • Instruction gets its source data from a register. • Data
resulting from the operation is stored in another register. • Data length depends on
register being used. – 8-bit registers: AH, AL, BH, BL, CH, CL, DH, DL. – 16-bit
registers: AX, BX, CX, DX, SP, BP, SI, DI. – 32-bit registers: EAX, EBX, ECX, EDX,
ESP, EBP, EDI, ESI. – 64-bit registers: RAX, RBX, RCX, RDX, RSP, RBP, RDI, RSI,
and R8 through R15.
9. 12. 1.Register Addressing • Examples: – MOV AX, BX ;Copy the 16-bit content of BX
to AX – MOV AL, BL ;Copy the 8-bit content of BL to AL – MOV SI, DI ;Copy DI into
SI – MOV DS, AX ;Copy AX into DS •

 Note that the instruction must use registers of the same size. – Cannot mix
between 8-bit and 16-bit registers. – Will result in an error when assembled.

10. Immediate Addressing • The source data is coded directly into the instruction. – The term
immediate means that the data immediately follows the hexadecimal opcode in the
memory. • Immediate data are constant data such as a number, a character, or an
arithmetic expression. • Examples: – MOV AX, 100 – MOV BX, 189CH – MOV AH,
10110110B – MOV AL, (2 + 3)/5
11. Direct Addressing • The operand is stored in a memory location, usually in data segment.
• The instruction takes the offset address. – This offset address must be put in a bracket
[ ]. • Example: – MOV [1234H], AL – The actual memory location is obtained by
combining the offset address with the segment address in the segment register DS (unless
specified otherwise) – If we want to use another segment register such as ES, you can use
the syntax ES:[1234H] – Assuming DS = 1000H, then this instruction will move the
content of AL into the memory location 1234H.
12. Register Indirect Addressing • Similar to direct data addressing, except that the offset
address is specified using an index or base register. – Base registers = BP, BX. Index
registers = DI, SI. – In 80386 and above, any register (EAX, EBX, ECX, EDX, EBP,

27
EDI, ESI) can store the offset address. – The registers must be specified using a bracket
[ ]. – DS is used as the default segment register for BX, DI and SI. • Example: – MOV
AX, [BX] – Assuming DS = 1000H and BX = 1234H, this instruction will move the
content memory location 11234H and 11235H into AX.
13. Base-plus-index Addressing • Similar to register indirect addressing, except that the
offset address is obtained by adding a base register (BP, BX) and an index register (DI,
SI). • Example: – MOV [BX+SI], BP – Assuming DS = 1000H, BX = 0300H and SI =
0200H, this instruction will move the content of register BP to memory location 10500H.
14. Register Relative Addressing • Similar to register indirect addressing, except that the
offset address is obtained by adding an index or base register with a displacement. •
Example 1: – MOV AX, [DI+100H] – Assuming DS = 1000H and DI = 0300H, this
instruction will move the content from memory location 10400H into AX. • Example 2: –
MOV ARRAY[SI], BL – Assuming DS = 1000H, ARRAY = 5000H and SI = 500H, this
instruction will move the content in register BL to memory location 15500H.
15. Base Relative-plus-index Addressing • Combines the base-plus-index addressing and
relative addressing. • Examples: – MOV AH, [BX+DI+20H] – MOV FILE[BX+DI], AX
– MOV LIST[BP+SI+4], AL
16. APPLY ASSEMBLY LANGUAGE
17. Write simple program in assembly language Example of assembly languange:

MOV CL, 55H ; move 55H into register CL MOV DL, CL ; copy the contents of CL into
DL (now DL=CL=55H) MOV AH, DL ; copy the contents of DL into AH (now
AH=CL=55H) MOV AL, AH ; copy the contents of AH into AL (now AL=AH=55H)
MOV BH, CL ; copy the contents of CL into BH (now BH=CL=55H) MOV CH, BH ;
copy the contents of BH into CH (now CH=BH=55H) HLT

Assembler

An assembler program creates object code by translating combinations of mnemonics and


syntax for operations and addressing modes into their numerical equivalents. This representation
typically includes an operation code ("opcode") as well as other control bits and data. The
assembler also calculates constant expressions and resolves symbolic names for memory
locations and other entities. The use of symbolic references is a key feature of assemblers, saving
tedious calculations and manual address updates after program modifications. Most assemblers
also include macro facilities for performing textual substitution – e.g., to generate common short
sequences of instructions as inline, instead of called subroutines.

Like early programming languages such as Fortran, Algol, Cobol and Lisp, assemblers have been
available since the 1950s and the first generations of text based computer interfaces. However,
assemblers came first as they are far simpler to write than compilers for high-level languages.
This is because each mnemonic along with the addressing modes and operands of an instruction
translates rather directly into the numeric representations of that particular instruction, without
much context or analysis. There have also been several classes of translators and semi automatic
code generators with properties similar to both assembly and high level languages, with
speedcode as perhaps one of the better known examples.

28
Number of passes

There are two types of assemblers based on how many passes through the source are needed
(how many times the assembler reads the source) to produce the executable program.

 One-pass assemblers go through the source code once. Any symbol used before it is
defined will require "errata" at the end of the object code (or, at least, no earlier than the
point where the symbol is defined) telling the linker or the loader to "go back" and
overwrite a placeholder which had been left where the as yet undefined symbol was used.
 Multi-pass assemblers create a table with all symbols and their values in the first passes,
then use the table in later passes to generate code.

In both cases, the assembler must be able to determine the size of each instruction on the initial
passes in order to calculate the addresses of subsequent symbols. This means that if the size of an
operation referring to an operand defined later depends on the type or distance of the operand,
the assembler will make a pessimistic estimate when first encountering the operation, and if
necessary pad it with one or more "no-operation" instructions in a later pass or the errata. In an
assembler with peephole optimization, addresses may be recalculated between passes to allow
replacing pessimistic code with code tailored to the exact distance from the target.

The original reason for the use of one-pass assemblers was speed of assembly – often a second
pass would require rewinding and rereading the program source on tape or rereading a deck of
cards or punched paper tape. With modern computers this has ceased to be an issue. The
advantage of the multi-pass assembler is that the absence of errata makes the linking process (or
the program load if the assembler directly produces executable code) faster.[5]

Example: in the following code snippet a one-pass assembler would be able to determine the
address of the backward reference BKWD when assembling statement S2, but would not be able
to determine the address of the forward reference FWD when assembling the branch statement
S1; indeed FWD may be undefined. A two-pass assembler would determine both addresses in
pass 1, so they would be known when generating code in pass 2,

S1 B FWD
...
FWD EQU *
...
BKWD EQU *
...
S2 B BKWD

RISC and CISC:

The RISC and CISC are technologies on which on which design and architecture of
microprocessor is based.

29
 RISC: It stands for Reduced Instruction Set Computer in which each instruction has
dedicated electronic circuitry made from gates, decoders etc to generate control signal. It
is a hardwired technique of designing processor unit. Example: DEC’s Alpha, Power PC,
ULTRASPARC
 CISC: It stands for Complex Instruction Set Computer based on microprogramming
techniques. The hardware is controlled by instructions coded in control memory.
Instruction is called microinstruction and coding process is called microprogramming.
Each microinstructions produces control signal to control hardware of computer. CISC is
more complex but less efficient processor designing technique.

Example: Intel 80486, Pentium I, Pentium II, Celeron, Pentium III

Difference between RISC and CISC:

Sn. RISC CISC


1. Small set of instruction with Large set of instructions with
fixed (32 bits) format and most variable format (16-64 bits per
register based instructions. instructions)
2. Addressing modes are limited 12-24 addressing modes
to 3-5
3. Large numbers (32-192) of 8-24 GPRs with a unified cache
GPRs (General Purpose for instruction and data, recent
Registers) with mostly split designs also use split caches.
data cache and instruction
cache.
4. Most hardwired without control Most micro-coded using
memory. memories (ROM), but modern
CISC also use hardwired
control.

30

You might also like