Chapter Two Basics of Assembly Language Programs: Introduction To Assembly Language. What Is Assembly Language?
Chapter Two 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.
• At one time many assembly language mnemonics were three letter abbreviations,
such as JMP for jump, INC for increment, etc.
• 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".
prepared by Berihun G. Msc in computer sc [AAU] 4
• 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.
• 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.
prepared by Berihun G. Msc in computer sc [AAU] 9
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.
• 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.
Prof. Swati R Sharma Unit 4 – Assembly Language Basics 12
Compilers and Assemblers
Positive Vibes:MPI is the interesting, easiest and scoring subject.
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 ++
prepared by Berihun G. Msc in computer sc [AAU] 14
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:
prepared by Berihun G. Msc in computer sc [AAU] 15
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).
prepared by Berihun G. Msc in computer sc [AAU] 16
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:
prepared by Berihun G. Msc in computer sc [AAU] 23
Continued …
• Operands: Assembly language instructions can have between zero and three
operands, each of which can be a register, memory operand, constant
expression Comments: Descriptions
1. Single-line comments, beginning with a
semicolon character (;).
2. Block comments, beginning with the
COMMENT directive and a user-specified
symbol.
COMMENT ! This is comment line ! Or
COMMENT & comment line &
• The STC instruction, for example, has no operands: stc ; set Carry flag
• The INC instruction has one operand: inc eax ; add 1 to EAX
• The MOV instruction has two operands: mov count,ebx ; move EBX to count
• 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 prepared
EAXbyregister.
Berihun G. Msc in computer sc [AAU] 24
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.