Professional Documents
Culture Documents
Basics of Assembly Language Programs: Introduction To Assembly Language. What Is Assembly Language?
Basics of Assembly Language Programs: Introduction To Assembly Language. What Is Assembly Language?
Mov al,2h
Mov dl,’a’
• Assembly language is the most basic programming language available for any processor.
• Modern processors have a much larger instruction set and many mnemonics
are now longer, for example FPATAN for "floating point particular tangent” and
BOUND for "check array index against bounds".
• In some assembly languages the same mnemonic such as MOV may refer
to a family of related OPCODES for loading, copying and moving data,
whether these are immediate values, values in registers, or memory
locations pointed to by values in registers.
• AL can use registers and main memory and HLL uses main memory.
• A stand-alone binary executable of compact size is required, i.e. one that must
execute without recourse to the run-time components or libraries associated
with a high-level language; this is perhaps the most common situation.
Here are the reasons people give for not using assembly:
• Improved compiler technology has eliminated the need for assembly language.
• Today, machines are so fast and have more memory that we no longer need to
use assembly.
• If you need more speed, you should use a better algorithm rather than switch to
assembly language.
Assembly language is:
• Hard to learn
• Hard to debug
• Hard to maintain
• Hard to write
• Speed. Assembly language programs are generally the fastest programs around.
• Knowledge. Your knowledge of assembly language will help you write better
programs, even when using HLLs.
Hierarchy of Languages
Application Program
• Native to a
High Level Language processor:
Machine Independent High Level Language
executed directly
Machine Specific Low Level Language by hardware
Assembly Language • Instructions
consist of binary
MOV BL,05h Machine Language • Assembly language is code: 1s and 0s
ADD CL
a low-level
MUL BH
programming
language designed for
Micro Program Control a specific type of
processor.
1100 1011 Hardware • Uses symbolic names
1100 1110 to represent
0100 1111 operations, registers
and memory
locations.
Compilers and Assemblers
High Level Language
Compiler
Assembler
Machine Language
Assemblers
1. MASM –Originally by Microsoft, it's now included in the MASM32v8 package, which
includes other tools as well.
2. TASM – Another popular assembler. Made by Borland but is still a commercial product, so
you cannot get it for free.
3. NASM –A free, open source assembler, which is also available for other platforms.
Editor:-
4. Emulator software[EMU8086] Notepad/ notepad ++
Textpad, VS code, Jedit
Basic Elements of Assembly Language
Integer Constants
• An integer constant (or integer literal) is made up of an optional leading
sign, one or more digits, and an optional suffix character (called a radix)
indicating the number’s base: [{+ | −}] digits [ radix]
• Radix may be one of the following (uppercase or lowercase):
If no radix is given, the integer constant is assumed to be decimal. Here are some
examples using different radixes:
Continued …
• Example:-
• A hexadecimal constant beginning with a letter must have a leading zero to prevent
the assembler from interpreting it as an identifier.
• Integer Expressions:-is a mathematical expression involving integer values and
arithmetic operators.
• It can store 32 bits (00000000h through FFFFFFFFh).
• The arithmetic operators are listed in the following table according to their precedence
order, from highest (1) to lowest (4).
Continued …
• Label:-is an identifier that acts as a place marker for instructions and data.
• A label placed just before an instruction implies the instruction’s address. Similarly, a label placed just before a
variable implies the variable’s address.
• Data Labels: A data label identifies the location of a variable, providing a convenient way to reference the variable in code.
Example;
Count DWORD 100
array DWORD 1024, 2048, 4096, 8192 ; It is possible to define multiple data items following a label.
Code Labels: A label in the code area of a program (where instructions are located) must end with a colon (:).
Are used as targets of jumping and looping instructions.
• For example, the following JMP (jump) instruction transfers control to the location marked by the label named target, creating a
loop:
− target:
− mov ax,bx
− ...
− jmp target
A code label can share the same line with an instruction, or it can be on a line by itself:
− L1: mov ax,bx
− L2:
Continued …
• The imul instruction has Three operands: imul eax,ebx,5 ;In this case, EBX is
multiplied by 5, and the product is stored in the EAX register.
Assembling, Linking, and Running Programs
• A source program written in assembly language cannot be executed directly
on its target computer. It must be translated, or assembled into executable
code.
• The assembler produces a file containing machine language called an object
file. This file isn’t quite ready to execute. It must be passed to another
program called a linker, which in turn produces an executable file.
Defining Data Types
• It describes a set of values that can be assigned to variables and
expressions of the given type.
• The essential characteristic of each type is its size in bits: 8, 16, 32, 48,
64
• A variable declared as DWORD, for example, logically holds an
unsigned 32-bit integer. In fact, it could hold a signed 32-bit integer, a
32-bit single precision real, or a 32-bit pointer. The assembler is not
case sensitive, so a directive such as DWORD can be written as dword,
Dword, dWord, and so on.
Instruction Mnemonic
• Is a short word that identifies an instruction. Assembly language
instruction mnemonics such as mov, add, and sub provide hints about
the type of operation they perform.
prepared by Berihun G. Msc in computer sc [AAU] 26
Following are examples of instruction mnemonics: