Introduction To Assembly Language Programming

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

ASSEMBLY LANGUAGE PROGRAMMING

Course description

The aim of this course is to introduce students to assembly language programming. By the end of
the course students should be able to write, test and debug programs in x86 assembly language
using assembler, debug and emulation software and relate assembly language with other
processor assembly languages and high level languages.
Purpose of the course

Concepts of assembly language and the machine representation of instructions and data of a
modern digital computer are presented. Students will have the opportunity to study machine
addressing, stack operations, subroutines, and programmed and interrupt driven I/O.

Expected Learning outcomes

 Ability to write Assembly Language programs for the Intel x86 Microprocessors.
 Knowledge of various addressing modes.
 Knowledge of data transfer instructions, arithmetic instructions, logic instructions, shift
instructions, and rotates instructions.
 Ability to decode and encode machine code by hand.
 Ability to examine and modify the contents of Memory.
 Knowledge of Control flow and loop instructions.

Introduction:

A language is the main medium of communicating between the Computer systems and the most
common are the programming languages. As we know a Computer only understands binary
numbers that is 0 and 1 to perform various operations but the languages are developed for
different types of work on a Computer. A language consists of all the instructions to make a
request to the system for processing a task. From the first generation and now fourth generation
of the Computers there were several programming languages used to communicate with the
Computer. Here we will go in the detail of the Computer language and its types.
Classifications of computer Languages

Computer Language Description:

A Computer language includes various languages that are used to communicate with a Computer
machine. Some of the languages like programming language which is a set of codes or
instructions used for communicating the machine. Machine code is also considered as a
computer language that can be used for programming. And also HTML which is a computer
language or a markup language but not a programming language. Similarly there are different
types of languages developed for different types of work to be performed by communicating
with the machine. But all the languages that are now available are categorized into two basic
types of languages including Low-level language and High level language
Low Level Language:

Low level languages are the machine codes in which the instructions are given in machine
language in the form of 0 and 1 to a Computer system. It is mainly designed to operate and
handle all the hardware and instructions set architecture of a Computer. The main function of the
Low level language is to operate, manage and manipulate the hardware and system components.
There are various programs and applications written in low level languages that are directly
executable without any interpretation or translation. The most famous and the base of all
programming languages “C” and “C++” are mostly used Low level languages till today. Low
level language is also divided into two parts are Machine language and Assembly language.

 Machine Language is one of the low-level programming languages which is the first
generation language developed for communicating with a Computer. It is written in
machine code which represents 0 and 1 binary digits inside the Computer string which
makes it easy to understand and perform the operations. As we know a Computer system
can recognize electric signals so here 0 stands for turning off electric pulse and 1 stands
for turning on electric pulse. It is very easy to understand by the Computer and also
increases the processing speed.
The main advantage of using Machine language is that there is no need of a translator or
interpreter to translate the code, as the Computer directly can understand. But there are some
disadvantages also like you have to remember the operation codes, memory address every time
you write a program and also hard to find errors in a written program. It is a machine dependent
and can be used by a single type of Computer.

 Assembly Language is the second generation programming language that has almost
similar structure and set of commands as Machine language. Instead of using numbers
like in Machine languages here we use words or names in English forms and also
symbols. The programs that have been written using words, names and symbols in
assembly language are converted to machine language using an Assembler. Because a
Computer only understands machine code languages that’s why we need an Assembler
that can convert the Assembly level language to Machine language so the Computer gets
the instruction and responds quickly.

The main disadvantage of this language is that it is written only for a single type of CPU and
does not run on any other CPU. But its speed makes it the most used low level language till
today which is used by many programmers.

High Level Language:

The high level languages are the most used and also more considered programming languages
that helps a programmer to read, write and maintain. It is also the third generation language that
is used and also running till now by many programmers. They are less independent to a
particular type of Computer and also require a translator that can convert the high level language
to machine language. The translator may be an interpreter and Compiler that helps to convert
into binary code for a Computer to understand. There is various high level programming
languages like C, FORTRAN or Pascal that are less independent and also enables the
programmer to write a program.

The Compiler plays an important role on the Computer as it can convert to machine language
and also checks for errors if any before executing. There are several high level languages that
were used earlier and also now like COBOL, FORTRAN, BASIC, C, C++, PASCAL, LISP,
Ada, Algol, Prolog and Java. It is user-friendly as the programs are written in English using
words, symbols, characters, numbers that needs to be converted to machine code for processing.

Conclusion:

Since these are some of the Computer languages which is unto third generation but there are also
4GL or fourth generation languages that are typical high level programming languages used for
accessing databases using commands. And you will be even happier with the fifth generation
language too that are used for artificial intelligence and neural networks for high professionals
like scientist. But the above programming languages are very close to humans and used to write
programs easily and convert to machine language for easy pickings for a Computer machine.

Compiling a Program

When you type cc at the command line a lot of stuff happens.

Normally the C’s program building process involves four stages and utilizes different ‘tools’
such as a preprocessor, compiler, assembler, and linker.

At the end there should be a single executable file.  Below are the stages that happen in order
regardless of the operating system/compiler and graphically illustrated below.
 Preprocessing is the first pass of any C compilation. It processes include-files,
conditional compilation instructions and macros.
 Compilation is the second pass. It takes the output of the preprocessor, and the source
code, and generates assembler source code.
 Assembly is the third stage of compilation. It takes the assembly source code and
produces an assembly listing with offsets. The assembler output is stored in an object file.

 Linking is the final stage of compilation. It takes one or more object files or libraries as
input and combines them to produce a single (usually executable) file. In doing so, it
resolves references to external symbols, assigns final addresses to procedures/functions
and variables, and revises code and data to reflect new addresses (a process called
relocation). 

Assembly level programming

Assembly level programming is very important to low-level embedded system design is used to
access the processor instructions to manipulate hardware.  It is a most primitive machine level
language is used to make efficient code that consumes less number of clock cycles and takes less
memory as compared to the high-level programming language. It is a complete hardware
oriented programing language to write a program the programmer must be aware of embedded
hardware.

Instruction cycle

An instruction cycle is the basic operation cycle of a computer. It is the process by which a
computer retrieves a program instruction from its memory, determines what actions the
instruction requires, and carries out those actions. This cycle is repeated continuously by the
central processing unit (CPU), from bootup to when the computer is shut down.
 Fetch

In the fetch cycle, the control unit looks at the program counter register (PC) to get the
memory address of the next instruction. It then requests this instruction from main
memory and places it in the instruction register (IR).

 Decode

Here, the control unit checks the instruction that is now stored within the instruction
register (IR). It looks at the instruction - which is just a sequence of 0s and 1s and decides
what needs to be done. Does the instruction say to add two numbers? Does it say to load
a value from memory? Where in memory? The control unit interprets the binary
instruction to answer questions like these.

 Execute

Now the control unit sends the signals that tell the ALU, memory, and other components
signals to cause them to perform the correct work.

Assembly Level Programming 8086

The assembly programming language is a low-level language which is developed by using


mnemonics. The microcontroller or microprocessor can understand only the binary language like
0’s or 1’s therefore the assembler convert the assembly language to binary language and store it
the memory to perform the tasks. Before writing the program the embedded designers must have
sufficient knowledge on particular hardware of the controller or processor, so first we required to
know hardware of 8086 processor.

Microprocessor

A microprocessors is simply a computer processor that has been configured into the design and
function of a microchip. It performs the instructions and tasks involved in computer processing

Three basic characteristics differentiate microprocessors:

 Instruction set: The set of instructions that the microprocessor can execute.
 bandwidth : The number of bitsprocessed in a single instruction.
 clock speed : Given in megahertz (MHz), the clock speed determines how many
instructions per second the processor can execute.

O V E R V IE W OF THE 80 X 86 F A M I L Y

The 80x86 family was first started in 1981 with the 8086 and the newest member is the Pentium
which was released thirteen years later in 1994. They are all backwards compatible with each
other but each new generation has added features and more speed than the previous chip. Today
there are very few computers in use that have the 8088 and 8086 chips in them as they are very
outdated and slow. The number of 286 or 386 based computers around is declining as today's
software becomes more and more demanding. Even 486's are being replaced by Pentiums. With
the Pentium PRO and the MMX based CPUs Intel keeps increasing performance and features.
As computers are used to manipulate various types of data, there has to be some physical places
where these data can be stored. Some of these places are the registers.

8086 Microprocessor
– It is a 16-bit μp.
– 8086 has a 20 bit address bus can access up to 220 memory locations (1 MB).
– It can support up to 64K I/O ports.
– It provides 14, 16 -bit registers.
– It has multiplexed address and data bus AD0- AD15 and A16 – A19.
– It requires single phase clock with 33% duty cycle to provide internal timing.
– 8086 is designed to operate in two modes, Minimum and Maximum.
– It can prefetches up to 6 instruction bytes from memory and put them in instr queue in
order to speed up instruction execution.
– It requires +5V power supply.

– A 40 pin dual in line package

Architectural Diagram of 8086:


The 8086 has two parts, the Bus Interface Unit (BIU) and the Execution Unit (EU).
– The BIU fetches instructions, reads and writes data, and computes the 20-bit address.
– The EU decodes and executes the instructions using the 16-bit ALU.

– The two units functions independently.

System Bus
System Bus: is a series of conductive traces of signal lines on the system board, which is used to
communicate between 8086 (cpu) and all other devices.

The system bus is made up of three functional parts:


 Data bus
 Address bus
 Control bus
8086/8088 Memory I/O port1 I/O
BIU portn

System bus

To read from memory, for example, the Bus Interface Unit puts the correct memory address onto
the Address Bus and puts the command to read from memory onto the Control Bus. All devices
connected to the bus see this address and command simultaneously, but only the memory-control
circuitry respond to it. The memory-control circuitry is then responsible for decoding the
address, retrieving the data from the appropriate memory chips, and placing the data onto the
Data Bus for retrieval by the BIU.

To write to memory, the BIU puts the memory address onto the Address Bus, the byte of data
onto the Data Bus, and a command to write data onto memory of the control bus. The memory-
control circuitry decodes the command and the address, retrieves the data from the Data Bus, and
stores it into the correct memory chips. All other circuitry simply ignores the command.

Communication with the many special-purpose microprocessors attached to the System Bus is
accomplished through I/O ports. I/O ports are used for the transfer of data between the
8086/8088 processor and the other support hardware within the system. The In and OUT
instructions tell the processor to input or output data through the I/O ports.

When executing an IN instruction, the BIU puts the I/O port address onto the Address Bus and
puts the command to input data onto the Control Bus. The circuitry on some peripheral device
attacked to the bus recognizes the red command and decodes the I/O port as the address of some
register within the peripheral device. It then retrieves the data from the register and places it onto
the Data Bus from which it is retrieved by the BIU and fed to the Execution Unit within the
processor.

To execute an OUT instruction, the BIU puts the command to output data onto the Control Bus,
and I/O address onto the Address Bus, and the data to be output onto the Data Bus. The circuitry
of a peripheral device is then responsible for recognizing the output command and the I/O
address and for retrieving the data from the data bus.

You might also like