0% found this document useful (0 votes)
6 views

assembly language

The document explains the levels of programming languages, focusing on machine language, assembly language, and high-level language. It details assembly language as a low-level language using mnemonics for readability, its advantages and disadvantages, and the structure of assembly language programs, including opcodes and operands. Additionally, it outlines the role of assemblers in converting assembly code to machine code and provides syntax rules for writing assembly language programs.

Uploaded by

ezekiel nyamu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

assembly language

The document explains the levels of programming languages, focusing on machine language, assembly language, and high-level language. It details assembly language as a low-level language using mnemonics for readability, its advantages and disadvantages, and the structure of assembly language programs, including opcodes and operands. Additionally, it outlines the role of assemblers in converting assembly code to machine code and provides syntax rules for writing assembly language programs.

Uploaded by

ezekiel nyamu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 6

Levels of Languages

Machine language
What the computer sees and deals with
Every command is a sequence of one or more numbers
 Set of fundamental instructions the machine can execute
 Expressed as a pattern of 1’s and 0’s

Assembly language
Command numbers replaced by letter sequences that are easier to read
Still have to work with the specifics of the machine itself
 Alphanumeric equivalent of machine language
 Mnemonics more human-oriented than 1’s and 0’s

High-level language
Make programming easier by describing operations in a natural language
A single command replaces a group of low-level assembly language
commands

1. Assembly Language

Assembly language is a low-level programming language that uses


symbolic instructions (mnemonics) to communicate directly with a
computer’s hardware. Each instruction in assembly corresponds to a
single machine code instruction.

Mnemonics:symbolic names used for machine instructions in


assembly language. They make code more readable compared to
binary or hexadecimal instructions.

Example:
MOV AX, 5 ; Move the value 5 into the AX register
ADD AX, 3 ; Add 3 to the value in the AX register
INT 21H ; Interrupt to terminate program or perform a function

Explanation:

o MOV: A mnemonic for moving data.


o ADD: A mnemonic for addition.
o INT: A mnemonic for interrupt.

Advantages and Disadvantages


Advantages:
1. Greater control over hardware
2. Efficient use of resources
3. Fast execution

Disadvantages:
 Complexity and difficulty in programming
 Lack of portability across different systems

An assembly language program instruction consists of two parts

Opcode (Operation Code)

The opcode specifies the operation or task that the CPU should
perform. It represents a specific machine instruction, such as addition,
subtraction, data transfer, or comparison.

Examples of Opcodes:

 MOV: Moves data from one location to another.


 ADD: Adds two numbers.
 SUB: Subtracts one number from another.
 MUL: Multiplies two numbers.
 DIV: Divides two numbers.
 CMP: Compares two values.
 JMP: Jumps to a different part of the program.
 INT: Issues an interrupt to the CPU (e.g., system calls).

2. Operands

The operands are the data, registers, memory locations, or constants


upon which the operation (opcode) acts. An instruction can have:

 No operand: For instructions like RET (return from a procedure).


 One operand: For instructions like INC EAX (increment the value in
the EAX register).
 Two operands: For most instructions, such as ADD EAX, EBX (add
the contents of EBX to EAX).

Operands can be:

 Registers: Internal CPU storage locations (e.g., EAX, EBX).


 Memory addresses: Locations in RAM (e.g., [0x400]).
 Immediate values: Constants or fixed values (e.g., 5).

2. Assembler

An assembler is a software tool that converts assembly language


programs into machine code (binary code) that the CPU can execute.

Most popular assemblers:

1. MASM (Microsoft Macro Assembler) - Used for x86 and x86-64


programming on Windows platforms.
2. NASM (Netwide Assembler) - A widely-used open-source assembler
for x86 and x86-64 architectures.

3. GAS (GNU Assembler) - Part of the GNU Binutils, commonly used on


Unix/Linux systems.
4. FASM (Flat Assembler) - A fast and lightweight assembler for x86
and x86-64 architectures.

Basic Structure of ALP Syntax

The general format for an ALP instruction is:


[Label] Mnemonic Operand(s) ; Comment

[ label: ] mnemonics [ operands ] [;comment ]

A square bracket ( [ ] ) indicates that the field is optional.

Components:

1. Label:
o A label is an optional identifier used to mark a specific line or
memory location in the code. It helps with branching or looping
by serving as a reference point.
o Labels are followed by a colon (:).

Example:
START: MOV AX, 5 ; 'START' is the label

2. Mnemonic:
o A mnemonic is the symbolic name for a CPU instruction. It
specifies the operation to be performed (e.g., move, add,
subtract).
o Mnemonics are predefined keywords in assembly language.

Examples:

o MOV (move data)


o ADD (add values)
o SUB (subtract values)
o JMP (jump to a label)
3. Operand(s):
o Operands are the data or memory addresses on which the
mnemonic operates. Instructions can have:
 Zero operands: No data required (e.g., RET, HLT).
 One operand: Involves a single register or memory (e.g.,
INC AX).
 Two operands: Involves source and destination (e.g.,
MOV AX, BX).

Types of operands:

o Immediate values: Literal values (e.g., 5, 0xFF).


o Registers: CPU registers (e.g., AX, BX).
o Memory locations: Direct or indirect memory addresses.

Examples:
MOV AX, 10 ; Immediate value (10) to AX
ADD AX, BX ; Add the value of BX to AX

4. Comment:
o Comments begin with a semicolon (;) and are ignored by the
assembler.
o They explain the purpose of the code and improve readability.

Example:
MOV AX, 10 ; Load value 10 into AX

3. Syntax Rules

To write a valid ALP, follow these rules:

1. Case Sensitivity:
o Most assemblers are not case-sensitive (e.g., MOV and mov are
treated the same).
o However, consistency is recommended for readability.
2. Instruction Order:
o Typically, one instruction per line.
o Use proper order when defining data, instructions, and labels.
3. Alignment:
o Align instructions and comments neatly for clarity.
4. Comments:
o Always comment on complex logic to make the code
understandable.

You might also like