0% found this document useful (0 votes)
3 views8 pages

CPE 409 Assembly Language Programming Lecture Note

The document provides an overview of assembly language programming, detailing the characteristics, advantages, and disadvantages of low-level programming languages like machine code and assembly language. It explains the levels of abstraction in programming languages, the importance of instruction sets, and the contexts in which machine code programming is justified. Additionally, it covers programming models, addressing modes, and various assembly language features, emphasizing the relationship between hardware and software.

Uploaded by

akpabioangel9
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)
3 views8 pages

CPE 409 Assembly Language Programming Lecture Note

The document provides an overview of assembly language programming, detailing the characteristics, advantages, and disadvantages of low-level programming languages like machine code and assembly language. It explains the levels of abstraction in programming languages, the importance of instruction sets, and the contexts in which machine code programming is justified. Additionally, it covers programming models, addressing modes, and various assembly language features, emphasizing the relationship between hardware and software.

Uploaded by

akpabioangel9
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

CPE 409 Assembly Language Programming (Units: 3 LH 45)

 Introduction
What is a programming language?
A programming language defines a set of instructions that are compiled together
to perform a specific task by the CPU (Central Processing Unit). The programming
language mainly refers to high-level languages such as C, C++, Pascal, Ada,
COBOL, etc.
Each programming language contains a unique set of keywords and syntax, which
are used to create a set of instructions. Thousands of programming languages
have been developed till now, but each language has its specific purpose. These
languages vary in the level of abstraction they provide from the hardware. Some
programming languages provide less or no abstraction while some provide higher
abstraction. Based on the levels of abstraction, they can be classified into two
categories:
 Low-level language
 High-level language

Low-level language
The low-level language is a programming language that provides no abstraction
from the hardware, and it is represented in 0 or 1 forms, which are the machine
instructions. The languages that come under this category are the Machine level
language and Assembly language.

Machine-level language
The machine-level language is a language that consists of a set of instructions that
are in the binary form 0 or 1. As we know that computers can understand only
machine instructions, which are in binary digits, i.e., 0 and 1, so the instructions
given to the computer can be only in binary codes. Creating a program in a
machine-level language is a very difficult task as it is not easy for the
programmers to write the program in machine instructions. It is error-prone as it is
not easy to understand, and its maintenance is also very high. A machine-level
language is not portable as each computer has its machine instructions, so if we
write a program in one computer will no longer be valid in another computer.
The different processor architectures use different machine codes, for example, a
PowerPC processor contains RISC architecture, which requires different code than
intel x86 processor, which has a CISC architecture.

Assembly Language
The assembly language contains some human-readable commands such as mov,
add, sub, etc. The problems which we were facing in machine-level language are
reduced to some extent by using an extended form of machine-level language
known as assembly language. Since assembly language instructions are written in
English words like mov, add, sub, so it is easier to write and understand.
As we know that computers can only understand the machine-level instructions, so
we require a translator that converts the assembly code into machine code. The
translator used for translating the code is known as an assembler.
The assembly language code is not portable because the data is stored in
computer registers, and the computer has to know the different sets of registers.
Page
1
Assembly language sits between machine code and high level language. While
high level languages use statements to form instructions, assembly language uses
mnemonics (short abbreviations). Each mnemonic directly corresponds with a
machine code instruction. As a result, assembly language is known as a one-to-one
language. Here are some examples of mnemonics:

Mnemoni
Action
c
LDA Loads a value from a memory address
STA Stores a value in a memory address
Adds the value held in a memory address to the value held in the
ADD
accumulator
SUB Subtracts from the accumulator the value held in a memory address
MOV Moves the contents of one memory address to another

 Language level of abstraction and effect on machine


Level of Abstraction refers to the degree of complexity or simplicity in representing
information, concepts or systems. It significantly affects machine performance,
efficiency and compatibility.
Language Levels
 Low-Level Languages (e.g., Assembly, Machine Code)
 Direct machine code execution
 Optimized performance
 Platform-specific
 Error-prone

 Mid-Level Languages (e.g., C, C++)


 Compiled to machine code
 Balanced performance and portability
 Memory management
 Error handling

 High-Level Languages (e.g., Java, Python)


 Interpreted or compiled
 Abstracted memory management
 Platform independence
 Slower performance

 Very High-Level Languages (e.g., Ruby, JavaScript)


 Interpreted
 Dynamic typing
 Simplified syntax
 Slowest performance
Effects on Machines
 Performance: Low-level languages generally faster
 Memory Usage: High-level languages may require more memory
 Platform Compatibility: High-level languages often more portable
Page
2
 Error Handling: Low-level languages require manual error handling
 Security: Low-level languages may introduce security risks

The image which is given below describes the abstraction level from hardware. As
we can observe from the below image that the machine language provides no
abstraction, assembly language provides less abstraction whereas high-level
language provides a higher level of abstraction.

The assembly code is not faster than machine code because the assembly
language comes above the machine language in the hierarchy, so it means that
assembly language has some abstraction from the hardware while machine
language has zero abstraction.

 Characteristics of machine code


 Low-level: Directly accesses hardware resources (e.g., registers, memory).
 Error-prone: Difficult to write, read and maintain.
 Platform-dependent: Not portable across different architectures.
 Instruction-set architecture*: Defines instruction formats and operations.
 Executable: Can be run directly by the computer's processor.
 Machine-specific: Unique to each computer architecture (e.g., x86, ARM).
 Compact: Typically more compact than high-level languages.
 Binary format: Machine code consists of 0s and 1s.

Advantages Disadvantages
1 Fast execution: Directly executable by Difficulty in programming: Error-prone
hardware. and time-consuming.
2 Low-level optimization: Fine-grained Platform dependence: Limited
control over hardware. portability.
3 Compact code: Efficient use of memory. Maintenance challenges: Difficult to
understand and modify.

Differences between Machine-Level language and Assembly language


The following are the differences between machine-level language and assembly
language:

Machine-level language Assembly language

The machine-level language comes at The assembly language comes above


the lowest level in the hierarchy, so it the machine language means that it has

Page
3
has zero abstraction level from the less abstraction level from the hardware.
hardware.

It cannot be easily understood by It is easy to read, write, and maintain.


humans.

The machine-level language is written The assembly language is written in


in binary digits, i.e., 0 and 1. simple English language, so it is easily
understandable by the users.

It does not require any translator as the In assembly language, the assembler is
machine code is directly executed by used to convert the assembly code into
the computer. machine code.

It is a first-generation programming It is a second-generation programming


language. language.

 Justification for Machine code Programming


Machine code programming is justified in specific circumstances where low-level
optimization, performance and control are essential.

Circumstances Justifying Machine Code Programming


 Operating System Development: Machine code is used for bootloaders,
device drivers and kernel development.
 Device Drivers: Direct hardware manipulation necessitates machine code
programming.
 Embedded Systems: Resource-constrained devices require optimized
machine code for efficient execution.
 Microcontroller Programming: Small-scale embedded systems often require
machine code.
 High-Performance Computing: Scientific simulations, cryptography and data
compression benefit from machine code optimizations.
 Reverse Engineering: Analyzing and modifying existing machine code is
essential.
 Malware Analysis: Understanding malicious code requires machine code
expertise.
 Legacy System Maintenance: Older systems may still use machine code.

 Instruction set and dependency on underlying processor


Instruction Set Architecture (ISA) defines the set of instructions a processor
understands, influencing performance, power consumption and compatibility.

Instruction Set Characteristics


 Instruction Length: Fixed (e.g., x86) or variable (e.g., ARM).
 Instruction Format: Opcode, operands and addressing mode.
 Addressing Modes: Register, immediate, memory or I/O.
 Data Types: Integer, floating-point, string or vector.
 Control Flow: Branching, looping and conditional execution.
Page
4
Processor Dependency
 CPU Architecture: x86, ARM, MIPS, PowerPC or SPARC.
 Microarchitecture: Pipelining, cache hierarchy and execution units.
 Register Set: Number and size of registers.
 Memory Organization: Virtual memory, paging and caching.
 I/O Interfaces: Communication with peripherals.

Instruction Set Types


 CISC (Complex Instruction Set Computing): x86, x64.
 RISC (Reduced Instruction Set Computing): ARM, MIPS.
 VLIW (Very Long Instruction Word): IA-64.
 EPIC (Explicitly Parallel Instruction Computing): Intel Itanium.

Instruction Set Extensions


 MMX/SSE (Multimedia Extensions): SIMD instructions.
 AVX (Advanced Vector Extensions): Enhanced SIMD.
 AES (Advanced Encryption Standard): Encryption acceleration.
 Virtualization Extensions: Virtual machine support.
 Intel 8086 microprocessor assembly language programming

To be treated in its own manual

 Programming model as resources available to programmer

A programming model represents the resources and abstractions available to a


programmer for developing software.
Programming Model Components
 Memory Model: Defines memory organization, allocation and access.
 Execution Model: Specifies instruction execution, control flow and threading.
 I/O Model: Describes input/output operations and device interaction.
 Data Model: Defines data types, structures and operations.
 Security Model: Specifies access control, authentication and encryption.

Programming Model Types


 Sequential Programming: Single-threaded execution.
 Concurrent Programming: Multi-threaded or multi-process execution.
 Parallel Programming: Simultaneous execution on multiple cores.
 Distributed Programming: Execution across multiple machines.
 Event-Driven Programming: Reactive programming with event handling.

Available Resources
 Processors/Cores: Execution units for instructions.
 Memory: RAM, cache, virtual memory and storage.
 I/O Devices: Input/output interfaces (e.g., keyboard, display).
 Network: Communication interfaces (e.g., Ethernet, Wi-Fi).
 Storage: Persistent data storage (e.g., hard drives, SSDs).
 Graphics Processing Units (GPUs): Accelerated graphics and computation.
 Specialized Cores: (e.g., neural network processing units).

Page
5
addressing modes
instruction format
instruction set- arithmetic
logical, string, branching
program control
machine control
input/output
assembler directives
and-assembling
additional 80x86/Pentium instructions
Modular programming
Interrupt and service routine
Interfacing of assembly language to C
Intel 80x87 floating point programming
Introduction to MMX and SSE programming
Motorola 680x0 assembly language programming
Extensive practical engineering problems solving in assembly language using
MASM for Intel, and cross-assembler for Motorola.

Levels of Abstraction
Assembly Language is a programming language that is sitting between Machine
Code and High-Level Languages, providing the following features:
 Symbolic representation: Assembly language makes use of mnemonic
instructions instead of binary codes e.g., MOV, ADD, DIV etc.
 Memory addressing: Assembly Language makes use of symbolic addresses in
the place of absolute addresses e.g., variables, labels.
 Basic arithmetic operations: Assembly Language supports simple arithmetic
and logical operations.
The Effects on Machines
There are both positive and negative effects of the use of assembly language
program in machines

Page
6
Advantages
 Efficient code generation: Assembly code translates directly to machine
code.
 Low-level optimization: Programmers can fine-tune performance-critical
sections.
 Hardware-specific control: Direct access to hardware resources (e.g.,
registers, I/O ports).
 Compact code: Assembly code is typically smaller than high-level language
code.
Disadvantages
 Platform dependence: Assembly code is specific to a particular CPU
architecture.
 Error-prone: Lack of high-level language features increases error likelihood.
 Time-consuming development: Assembly programming requires manual
memory management.
 Limited portability: Code may not run on different hardware platforms.

Assembly
Physical Level: This level of abstraction focuses on hardware components,
[Link] physical properties of the system
The components of Physicla Level are
Transistors
Diodes
Resistors
Capacitors
inductors
2. *Logical Level*: Digital logic, binary operations.
3. *Software Level*: Programming languages, algorithms.
4. *Application Level*: User interfaces, functionality.
5. *Conceptual Level*: Abstract ideas, theoretical models.

In computer science, an abstraction level is a generalization of a conceptual model


or algorithm, away from any specific implementation. These generalizations arise
from broad similarities that are best encapsulated by models that express
Page
7
similarities present in various specific implementations. The simplification provided
by a good abstraction level allows for easy reuse by distilling a useful concept or
design pattern so that situations, where it may be accurately applied, can be
quickly recognized. Just composing lower-level elements into a construct doesn't
count as an abstraction layer unless it shields users from its underlying complexity.

characteristics of machine code, advantages, justifications of machine code


programming, instruction set and dependency on underlying processor. Intel 8086
microprocessor assembly language programming: Programming model as
resources available to programmer, addressing modes, instruction format,
instruction set- arithmetic, logical, string, branching, program control, machine
control, input/output ,etc; assembler directives, hand-assembling, additional
80x86/Pentium instructions. Modular programming. Interrupt and service routine.
Interfacing of assembly language to C . Intel 80x87 floating point programming.
Introduction to MMX and SSE programming. Motorola 680x0 assembly language
programming. Extensive practical engineering problems solving in assembly
language using MASM for Intel, and cross-assembler for Motorola.

Page
8

You might also like