SlideShare a Scribd company logo
ALP Programming
INTRODUCTION TO ASSEMBLY LANGUAGE PROGRAMMING
Rahul P
What is Assembly Language?
• An assembly (or assembler) language, often abbreviated asm, is a low-level
programming language for a computer, or other programmable device, in
which there is a very strong (generally one-to-one) correspondence
between the language and the architecture's machine code instructions.
• Assembly language is converted into executable machine code by a utility
program referred to as an assembler. The conversion process is referred to
as assembly, or assembling the source code. Assembly time is the
computational step where an assembler is run.
• Assembly language uses a mnemonic to represent each low-level machine
instruction or opcode, typically also each architectural register, flag, etc.
Many operations require one or more operands in order to form a complete
instruction and most assemblers can take expressions of numbers and
named constants as well as registers and labels as operands, freeing the
programmer from tedious repetitive calculations.
Assembler
An assembler is a program that takes basic computer instructions and
converts them into a pattern of bits that the computer's processor can use to
perform its basic operations. Some people call these instructions assembler
language and others use the term assembly language.
NASM
The Netwide Assembler (NASM) is an assembler and disassembler for
the Intel x86 architecture. It can be used to write 16-bit, 32-bit (IA-32)
and 64-bit (x86-64) programs. NASM is considered to be one of the most
popular assemblers for Linux.
Installing NASM in Ubuntu
Step 1 :
Open terminal in Ubuntu ( Alt + Ctrl + T )
Step 2 :
run the update command
sudo apt-get update
(apt-get update downloads the package lists from the repositories and "updates" them to get
information on the newest versions of packages and their dependencies. It will do this for all
repositories and PPA)
Step 3:
run NASM installation command
sudo apt-get install nasm
After the terminal processes complete, NASM is successfully installed in your system
Assembly - Basic Syntax
An assembly program can be divided into three sections −
•The data section,
•The bss section, and
•The text section.
The data Section
The data section is used for declaring initialized data or constants.
This data does not change at runtime. You can declare various constant
values, file names, or buffer size, etc., in this section.
The syntax for declaring data section is −
>> section.data
The bss Section
The bss section is used for declaring variables. The syntax for
declaring bss section is −
>> section.bss
The text section
The text section is used for keeping the actual code. This section must
begin with the declaration global _start, which tells the kernel where the
program execution begins.
The syntax for declaring text section is −
>> section.text
global _start
_start:
Comments
Assembly language comment begins with a semicolon (;). It may contain any
printable character including blank. It can appear on a line by itself, like −
The syntax for declaring text section is −
; This is a comment in your program code
or, on the same line along with an instruction, like −
add eax , ebx ; add ebx to eax
Assembly Language Statements
Assembly language programs consist of three types of statements −
• Executable instructions
• Assembler directives
• Macros.
• The executable instructions or simply instructions tell the processor what to
do. Each instruction consists of an operation code (opcode). Each executable
instruction generates one machine language instruction.
• The assembler directives tell the assembler about the various aspects of the
assembly process. These are non-executable and do not generate machine
language instructions.
• The Macros are basically a text substitution mechanism.
SYSTEM CALLS
System calls are APIs for the interface between the user space and the
kernel space.
Linux System Calls
We can make use of Linux system calls in our assembly programs. The
following steps are needed for using Linux system calls in our program:
Put the system call number in the EAX register.
Store the arguments to the system call in the registers EBX, ECX, etc.
Call the relevant interrupt (80h).
The result is usually returned in the EAX register.
Linux System Calls ( continues )
The following code snippet shows the use of the system call sys_exit:
mov eax,1 ; system call number (sys_exit)
int 0x80 ; call kernel
The following code snippet shows the use of the system call sys_write:
mov edx,4 ; message length
mov ecx,msg ; message to write
mov ebx,1 ; file descriptor (stdout)
mov eax,4 ; system call number (sys_write)
int 0x80 ; call kernel
Linux syscall numbers
Name Number in eax
sys_restart_syscall 0x00
sys_exit 0x01
sys_fork 0x02
sys_read 0x03
sys_write 0x04
sys_open 0x05
sys_close 0x06
File Descriptor
A file descriptor is a 16-bit integer assigned to a file as a file id. When
a new file is created or an existing file is opened, the file descriptor is used for
accessing the file.
File descriptor of the standard file streams –
stdin - 0
stdout - 1
stderr - 2
The Hello World Program in Assembly
section .data
msg db 'Hello, world!', 0xa ;string to be printed
len equ $ - msg ;length of the string
section .text
global _start ;must be declared for linker (ld)
section .bss
_start: ;tells linker entry point
mov edx,len ;message length
mov ecx,msg ;message to write
;call kernel
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80
mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel
Compiling and Linking an Assembly Program
Step 1:
Type the code using a text editor and save it as filename.asm
Step 2:
Make sure that you are in the same directory as where you
saved filename.asm.
Step3 :
To assemble the program, type nasm -f elf filename.asm
(If there is any error, you will be prompted about that at this stage. )
Step 4:
To link the object file and create an executable file, type
ld -m elf_i386 -s -o filename filename.o
Step 5 :
Execute the program by typing ./hello
Knowledge is
having the right
ANSWER.
Intelligence is
asking the right
QUESTION.
?
Rahul P

More Related Content

PPTX
Intro to assembly language
PPTX
Assembly language
PPT
Assembly language programming(unit 4)
PPTX
Assembly Language
PDF
Assembly level language
PPTX
Register & flags
PPTX
Pentium processor
Intro to assembly language
Assembly language
Assembly language programming(unit 4)
Assembly Language
Assembly level language
Register & flags
Pentium processor

What's hot (20)

PPTX
Interrupts
PPTX
Assembly language programming
PPTX
Microoperations
PPTX
Part I:Introduction to assembly language
PDF
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
PPTX
Booting and Start-up Sequence
PDF
Basics of digital verilog design(alok singh kanpur)
PDF
8086 instruction set (with simulator)
PPTX
Instruction sets of 8086
PPTX
computer organization and assembly language Lec 01 coal_introduction
PPTX
General register organization (computer organization)
PPTX
Register organization, stack
PPTX
COMPUTER INSTRUCTIONS & TIMING & CONTROL.
PPTX
Instruction Set Architecture
PPT
Computer Organization and Architecture.
PPT
Pin Description Diagram of Intel 80386 DX Microprocessor
PPT
Assembly language programming_fundamentals 8086
PPTX
Floating point arithmetic operations (1)
PPTX
Unit 4-booth algorithm
PPTX
Chapter 1 Introduction to Digital Logic
Interrupts
Assembly language programming
Microoperations
Part I:Introduction to assembly language
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
Booting and Start-up Sequence
Basics of digital verilog design(alok singh kanpur)
8086 instruction set (with simulator)
Instruction sets of 8086
computer organization and assembly language Lec 01 coal_introduction
General register organization (computer organization)
Register organization, stack
COMPUTER INSTRUCTIONS & TIMING & CONTROL.
Instruction Set Architecture
Computer Organization and Architecture.
Pin Description Diagram of Intel 80386 DX Microprocessor
Assembly language programming_fundamentals 8086
Floating point arithmetic operations (1)
Unit 4-booth algorithm
Chapter 1 Introduction to Digital Logic
Ad

Similar to Introduction to Assembly Language Programming (20)

PPTX
ASSEMBLY LANGUAGE.pptx
PPTX
NASM Introduction.pptx
PPT
LINUX Device Drivers
PDF
N_Asm Assembly basic syntax (sol)
PPTX
amr_systemsdadwdsdasdsadsadsaaddsdw.pptx
PPT
Assembly language
PDF
N_Asm Assembly system calls (sol)
PPT
Lec 01 basic concepts
PDF
microprocesser-140306112352-phpapp01.pdf
PPTX
2ProgrammerViewOfComputerAndInstructionCycle.pptx
DOCX
1 Describe different types of Assemblers.Assembly language.docx
PPTX
How To Add System Call In Ubuntu OS
PDF
Dive into exploit development
PPTX
weekly assessment with a perfect examples
PPTX
weekly assessment and some other components
PPT
Introduction To Computer and Java
DOCX
64-bit Assembly language program to Accept and display numbers.docx
PPT
CISY 105 Chapter 1
PPT
My cool new Slideshow!
ASSEMBLY LANGUAGE.pptx
NASM Introduction.pptx
LINUX Device Drivers
N_Asm Assembly basic syntax (sol)
amr_systemsdadwdsdasdsadsadsaaddsdw.pptx
Assembly language
N_Asm Assembly system calls (sol)
Lec 01 basic concepts
microprocesser-140306112352-phpapp01.pdf
2ProgrammerViewOfComputerAndInstructionCycle.pptx
1 Describe different types of Assemblers.Assembly language.docx
How To Add System Call In Ubuntu OS
Dive into exploit development
weekly assessment with a perfect examples
weekly assessment and some other components
Introduction To Computer and Java
64-bit Assembly language program to Accept and display numbers.docx
CISY 105 Chapter 1
My cool new Slideshow!
Ad

Recently uploaded (20)

PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
AI in Product Development-omnex systems
PPTX
Introduction to Artificial Intelligence
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
CHAPTER 2 - PM Management and IT Context
PPT
Introduction Database Management System for Course Database
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPTX
Transform Your Business with a Software ERP System
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Nekopoi APK 2025 free lastest update
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
ISO 45001 Occupational Health and Safety Management System
Which alternative to Crystal Reports is best for small or large businesses.pdf
Navsoft: AI-Powered Business Solutions & Custom Software Development
AI in Product Development-omnex systems
Introduction to Artificial Intelligence
How to Migrate SBCGlobal Email to Yahoo Easily
VVF-Customer-Presentation2025-Ver1.9.pptx
Odoo POS Development Services by CandidRoot Solutions
Understanding Forklifts - TECH EHS Solution
CHAPTER 2 - PM Management and IT Context
Introduction Database Management System for Course Database
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
How to Choose the Right IT Partner for Your Business in Malaysia
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Transform Your Business with a Software ERP System
Design an Analysis of Algorithms I-SECS-1021-03
Nekopoi APK 2025 free lastest update
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
ISO 45001 Occupational Health and Safety Management System

Introduction to Assembly Language Programming

  • 1. ALP Programming INTRODUCTION TO ASSEMBLY LANGUAGE PROGRAMMING Rahul P
  • 2. What is Assembly Language? • An assembly (or assembler) language, often abbreviated asm, is a low-level programming language for a computer, or other programmable device, in which there is a very strong (generally one-to-one) correspondence between the language and the architecture's machine code instructions. • Assembly language is converted into executable machine code by a utility program referred to as an assembler. The conversion process is referred to as assembly, or assembling the source code. Assembly time is the computational step where an assembler is run. • Assembly language uses a mnemonic to represent each low-level machine instruction or opcode, typically also each architectural register, flag, etc. Many operations require one or more operands in order to form a complete instruction and most assemblers can take expressions of numbers and named constants as well as registers and labels as operands, freeing the programmer from tedious repetitive calculations.
  • 3. Assembler An assembler is a program that takes basic computer instructions and converts them into a pattern of bits that the computer's processor can use to perform its basic operations. Some people call these instructions assembler language and others use the term assembly language. NASM The Netwide Assembler (NASM) is an assembler and disassembler for the Intel x86 architecture. It can be used to write 16-bit, 32-bit (IA-32) and 64-bit (x86-64) programs. NASM is considered to be one of the most popular assemblers for Linux.
  • 4. Installing NASM in Ubuntu Step 1 : Open terminal in Ubuntu ( Alt + Ctrl + T ) Step 2 : run the update command sudo apt-get update (apt-get update downloads the package lists from the repositories and "updates" them to get information on the newest versions of packages and their dependencies. It will do this for all repositories and PPA) Step 3: run NASM installation command sudo apt-get install nasm After the terminal processes complete, NASM is successfully installed in your system
  • 5. Assembly - Basic Syntax An assembly program can be divided into three sections − •The data section, •The bss section, and •The text section.
  • 6. The data Section The data section is used for declaring initialized data or constants. This data does not change at runtime. You can declare various constant values, file names, or buffer size, etc., in this section. The syntax for declaring data section is − >> section.data
  • 7. The bss Section The bss section is used for declaring variables. The syntax for declaring bss section is − >> section.bss
  • 8. The text section The text section is used for keeping the actual code. This section must begin with the declaration global _start, which tells the kernel where the program execution begins. The syntax for declaring text section is − >> section.text global _start _start:
  • 9. Comments Assembly language comment begins with a semicolon (;). It may contain any printable character including blank. It can appear on a line by itself, like − The syntax for declaring text section is − ; This is a comment in your program code or, on the same line along with an instruction, like − add eax , ebx ; add ebx to eax
  • 10. Assembly Language Statements Assembly language programs consist of three types of statements − • Executable instructions • Assembler directives • Macros. • The executable instructions or simply instructions tell the processor what to do. Each instruction consists of an operation code (opcode). Each executable instruction generates one machine language instruction. • The assembler directives tell the assembler about the various aspects of the assembly process. These are non-executable and do not generate machine language instructions. • The Macros are basically a text substitution mechanism.
  • 11. SYSTEM CALLS System calls are APIs for the interface between the user space and the kernel space. Linux System Calls We can make use of Linux system calls in our assembly programs. The following steps are needed for using Linux system calls in our program: Put the system call number in the EAX register. Store the arguments to the system call in the registers EBX, ECX, etc. Call the relevant interrupt (80h). The result is usually returned in the EAX register.
  • 12. Linux System Calls ( continues ) The following code snippet shows the use of the system call sys_exit: mov eax,1 ; system call number (sys_exit) int 0x80 ; call kernel The following code snippet shows the use of the system call sys_write: mov edx,4 ; message length mov ecx,msg ; message to write mov ebx,1 ; file descriptor (stdout) mov eax,4 ; system call number (sys_write) int 0x80 ; call kernel
  • 13. Linux syscall numbers Name Number in eax sys_restart_syscall 0x00 sys_exit 0x01 sys_fork 0x02 sys_read 0x03 sys_write 0x04 sys_open 0x05 sys_close 0x06
  • 14. File Descriptor A file descriptor is a 16-bit integer assigned to a file as a file id. When a new file is created or an existing file is opened, the file descriptor is used for accessing the file. File descriptor of the standard file streams – stdin - 0 stdout - 1 stderr - 2
  • 15. The Hello World Program in Assembly section .data msg db 'Hello, world!', 0xa ;string to be printed len equ $ - msg ;length of the string section .text global _start ;must be declared for linker (ld) section .bss _start: ;tells linker entry point mov edx,len ;message length mov ecx,msg ;message to write ;call kernel mov ebx,1 ;file descriptor (stdout) mov eax,4 ;system call number (sys_write) int 0x80 mov eax,1 ;system call number (sys_exit) int 0x80 ;call kernel
  • 16. Compiling and Linking an Assembly Program Step 1: Type the code using a text editor and save it as filename.asm Step 2: Make sure that you are in the same directory as where you saved filename.asm. Step3 : To assemble the program, type nasm -f elf filename.asm (If there is any error, you will be prompted about that at this stage. ) Step 4: To link the object file and create an executable file, type ld -m elf_i386 -s -o filename filename.o Step 5 : Execute the program by typing ./hello
  • 17. Knowledge is having the right ANSWER. Intelligence is asking the right QUESTION. ?