SlideShare a Scribd company logo
3
Most read
5
Most read
16
Most read
Assembly Language
General purpose registers on the x86 architecture
• eax is a 32-bit general-purpose register with two common uses: to
store the return value of a function and as a special register for
certain calculations. It is technically a volatile register, since the
value isn't preserved. Instead, its value is set to the return value of a
function before a function returns. eax is also used specifically in
certain calculations, such as multiplication and division, as a special
register.
• ebx is a non-volatile general-purpose register. It has no specific
uses, but is often set to a commonly used value (such as 0)
throughout a function to speed up calculations.
• ecx is a volatile general-purpose register that is occasionally used
as a function parameter or as a loop counter.
• edx is a volatile general-purpose register that is occasionally used
as a function parameter. It is generally used for storing short-term
variables within a function.
General purpose registers on the x86 architecture
• esi is a non-volatile general-purpose register that is often used as a
pointer. esi often stores data that is used throughout a function
because it doesn't change.
• edi is a non-volatile general-purpose register that is often used as a
pointer. It is similar to esi, except that it is generally used as a
destination for data.
• ebp is a non-volatile general-purpose register that has two distinct
uses depending on compile settings: it is either the base pointer or a
general purpose register.
• esp is a special register that stores a pointer to the top of the stack.
The value of esp must be the same at the beginning and the end of
each function.
General Purpose Registers
Special Purpose Registers
• eip, or the instruction pointer, is a special-purpose register which stores a
pointer to the address of the instruction that is currently executing.
• The flags register, where each bit has a specific meaning and they are
used to store meta-information about the results of previous operations.
The Stack
• The stack register, esp, is basically a register that points to an
arbitrary location in memory called "the stack". The stack is just a
really big section of memory where temporary data can be stored
and retrieved. When a function is called, some stack space is
allocated to the function, and when a function returns the stack
should be in the same state it started in.
• The stack always grows downwards, towards lower values. The esp
register always points to the lowest value on the stack. Anything
below esp is considered free memory that can be overwritten.
• The stack stores function parameters, local variables, and the
return address of every function.
Simple Instructions
• Pointers and Dereferencing
– eax -- is the value stored in eax
– [eax] -- is the value pointed to by eax
• Doing Nothing
– nop is short for "no operation" and it does nothing.
• Moving Data Around
– mov can move data between a register and memory, two registers, or a
constant to a register. movsx and movzx are special versions of mov
which are designed to be used between signed (movsx) and unsigned
(movzx) registers of different sizes.
Simple Instructions
• lea (load effective address)
– lea is very similar to mov, except that math can be done on the original
value before it is used. The "[" and "]" characters always surround the
second parameter, but in this case they do not indicate dereferencing.
– lea is generally used for calculating array offsets, since the address of
an element of the array can be found with [arraystart + offset*datasize].
Simple Instructions: Math and Logic
• add, sub:
– A register can have either another register, a constant value, or a
pointer added to or subtracted from it.
• inc, dec:
– These instructions simply increment and decrement a register.
Simple Instructions: Math and Logic
• and, or, xor, neg:
– All logical instructions are bitwise.
– Bitwise operation: Each bit in the two operands has the operation
done between them, and the result is stored in the first one.
Simple Instructions: Math and Logic
• mul, imul, div, idiv:
– Both multiplication and division make use of the 64-bit register edx:eax.
• div divides the 64-bit value in edx:eax by the operand, and stores the
quotient in eax. The remainder (modulus) is stored in edx. div does both
division and modular division, at the same time.
Simple Instructions: Math and Logic
• cdq:
– cdq is generally used immediately before idiv. It stands for "convert
double to quad." In other words, convert the 32-bit value in eax to the
64-bit value in edx:eax.
Simple Instructions: Math and Logic
• shl, shr, sal, sar: shl - shift left, shr - shift right, sal - shift
arithmetic left, sar - shift arithmetic right.
– These are used to do a binary shift, equivalent to the C operations <<
and >>. They each take two operations: the register to use, and the
number of places to shift the value in the register.
Jumping Around
• jmp:
– jmp, or jump, sends the program execution to the specified address no
matter what.
• call, ret:
– call is similar to jump, except that in addition to sending the program to
the specified address, it also saves ("pushes") the address of the
executable instruction onto the stack.
– ret removes ("pops") the first value off of the stack, and jumps to it. In
almost all cases, this value was placed onto the stack by the call
instruction. If the stack pointer is at the wrong location, or the saved
address was overwritten, ret attempts to jump to an invalid address
which usually crashes the program.
Jumping Around
– ret can also have a parameter. This parameter is added to the stack
immediately after ret executes its jump.
– The combination of call and ret are used to implement functions.
Jumping Around
• cmp, test:
– cmp, or compare, compares two operands and sets or unsets flags in
the flags register based on the result.
– Specialized jump commands can check these flags to jump on certain
conditions.
– test is very similar to cmp, except that it performs a bitwise 'and'
operation between the two operands. test is most commonly used to
compare a variable to itself to check if it's zero.
• jz/je, jnz/jne, jl/jb, jg, jle, jge:
– jz and je (which are synonyms) will jump to the address specified if and
only if the 'zero' flag is set, which indicates that the two values were
equal. In other words, "jump if equal".
– jnz and jne (which are also synonyms) will jump to the address
specified if and only if the 'zero' flag is not set, which indicates that the
two values were not equal. In other words, "jump if different".
– jl and jb (which are synonyms) jumps if the first parameter is less than
the second.
– jg jumps if the first parameter is greater than the second.
– jle jumps if the 'less than' or the 'zero' flag is set, so "less than or equal
to".
– jge jumps if the first is "greater than or equal to" the second.
Jumping Around
• Examples:
Manipulating the Stack
• push, pop:
– push decrements the stack pointer by the size of the operand, then
saves the operand to the new address.
– pop sets the operand to the value on the stack, then increments the
stack pointer by the size of the operand.
String Instructions
• String - a byte or word array:
– Operations that can be performed with string instructions:
• copy a string into another string
• search a string for a particular byte or word
• store characters in a string
• compare strings of characters alphanumerically
• Direction Flag (DF):
• one of 8086 processor control flags.
• controls the direction of string operations:
• DF = 0 => forward (left to right) processing
• DF = 1 => backward (right to left) processing
• CLD - clears the DF; sets DF = 0
• STD - sets DF = 1
String Instructions
• Moving (Copying) Strings:
• Instruction: MOVS( /B/W/D) dest, src
– MOVSB - copies contents of BYTE given by DS:SI into ES:DI
– MOVSW - copies contents of WORD given by DS:SI into ES:DI
– MOVSD - copies contenst of DOUBLE WORD given by DS:SI into
ES:DI
• Comparing Strings:
• Instruction: CMPS src, dest
– The CMPSB(W) instruction can be used to compare a byte(word) in
one string (DS:offset in SI) with a byte (word) in another string
(ES:offset in DI).
String Instructions
• Scan String:
• Instruction: SCAS <String>
– SCAS(/B/W) compares a byte in AL or a word in AX with a byte or word
pointed to by DI in ES.
• load String:
• Instruction: LODS <String>
– This instruction copies a byte (word) of string from the location pointed to by
SI.
• Store String:
• Instruction: STOS <String>
– The STOS instruction copies a byte (word) from AL (AX) to a memory
location stored in [ES:DI].
Repetition Prefixes
• REP:
– REP is a prefix written before one of the string instructions. It is used for
repeating an instruction count number of times, where count is stored in
the CX register. After every operation the CX register is decremented
and the zero flag is tested; the process continues till CX = 0.
• REP/REPE/REPNE/REPZ/REPNZ: The REP prefix also has the
following variations:
– REP: It is the unconditional repeat. It repeats the operation until CX is
zero.
– REPE or REPZ: It is conditional repeat. It repeats the operation while
the zero flag indicates equal/zero. It stops when the ZF indicates not
equal/zero or when CX is zero.
– REPNE or REPNZ: It is also conditional repeat. It repeats the operation
while the zero flag indicates not equal/zero. It stops when the ZF
indicates equal/zero or when CX is decremented to zero.
DOS Interrupts
• Input a character:
– MOV AH, 01h
– INT 21h
• Input a string:
– MOV DX, Buffer
– MOV AH, 0Ah
– INT 21h
 Load the desired character into DL & DX, then call the interrupt with function
code in AH.
• Output a character:
– MOV DL, ...
– MOV AH, 02h
– INT 21h
• Output a string:
– MOV DX, ...
– MOV AH, 09h
– INT 21h
Thank You

More Related Content

PPT
SWITCH CASE STATEMENT IN C
PDF
Assembly level language
DOCX
Introduction to CPU registers
PPTX
Addressing modes
PPT
Binary.ppt
PPT
Multiway Trees.ppt
PPTX
Introduction to Assembly Language Programming
PPTX
Searching & Algorithms IN DATA STRUCTURES
SWITCH CASE STATEMENT IN C
Assembly level language
Introduction to CPU registers
Addressing modes
Binary.ppt
Multiway Trees.ppt
Introduction to Assembly Language Programming
Searching & Algorithms IN DATA STRUCTURES

What's hot (20)

PPTX
OS disk structure (1).pptx
PPTX
1.1.2 HEXADECIMAL
PPTX
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
PPTX
Data transfer and manipulation
PPTX
Introduction To EMU
PPT
10 instruction sets characteristics
PPT
1327 Addressing Modes Of 8086
PPT
Conversion of number system
PDF
Singly linked list
PDF
Trie Data Structure
PPT
Lecture_ASCII and Unicode.ppt
PDF
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
PPT
The Intel 8086 microprocessor
DOCX
Central processing unit
PDF
Heap Tree.pdf
PPTX
Assembly language
PPTX
SQL Server 2016 Tablas en Memoria
PPT
Visual Basic 6.0
PPT
OS disk structure (1).pptx
1.1.2 HEXADECIMAL
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Data transfer and manipulation
Introduction To EMU
10 instruction sets characteristics
1327 Addressing Modes Of 8086
Conversion of number system
Singly linked list
Trie Data Structure
Lecture_ASCII and Unicode.ppt
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
The Intel 8086 microprocessor
Central processing unit
Heap Tree.pdf
Assembly language
SQL Server 2016 Tablas en Memoria
Visual Basic 6.0
Ad

Similar to Assembly language (20)

PPTX
Introduction to debugging linux applications
PPTX
Reversing malware analysis training part4 assembly programming basics
PPTX
Reversing & Malware Analysis Training Part 4 - Assembly Programming Basics
PPT
PPT
8086 microprocessor assembler directives.ppt
PPTX
X86 operation types
PPTX
Introduction to Assembly Language
PDF
Reversing & malware analysis training part 4 assembly programming basics
PPTX
[ASM]Lab8
PPTX
MES_MODULE 2.pptx
PPTX
Lecture 12 Bottom-UP Parsing.pptx
PPT
Instruction set
DOCX
Assembly language
PPTX
Coal (1)
PDF
(8) cpp stack automatic_memory_and_static_memory
PDF
Supporting Arrays and Allocatables in LFortran
PPTX
Arrays, Strings & Loops in assembly Language.pptx
PDF
04basic Concepts
PPTX
Microprocessor.pptx
PPTX
Introduction to debugging linux applications
Reversing malware analysis training part4 assembly programming basics
Reversing & Malware Analysis Training Part 4 - Assembly Programming Basics
8086 microprocessor assembler directives.ppt
X86 operation types
Introduction to Assembly Language
Reversing & malware analysis training part 4 assembly programming basics
[ASM]Lab8
MES_MODULE 2.pptx
Lecture 12 Bottom-UP Parsing.pptx
Instruction set
Assembly language
Coal (1)
(8) cpp stack automatic_memory_and_static_memory
Supporting Arrays and Allocatables in LFortran
Arrays, Strings & Loops in assembly Language.pptx
04basic Concepts
Microprocessor.pptx
Ad

More from Piyush Jain (6)

PPTX
Logging, monitoring and auditing
PDF
Incident response methodology
PDF
Understanding security operation.pptx
PPTX
Identity and access management
PPTX
Security architecture, engineering and operations
PPT
Windows internals
Logging, monitoring and auditing
Incident response methodology
Understanding security operation.pptx
Identity and access management
Security architecture, engineering and operations
Windows internals

Recently uploaded (20)

PPT
Teaching material agriculture food technology
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
cloud_computing_Infrastucture_as_cloud_p
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
Encapsulation theory and applications.pdf
PDF
August Patch Tuesday
PPTX
Spectroscopy.pptx food analysis technology
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Tartificialntelligence_presentation.pptx
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Machine Learning_overview_presentation.pptx
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PPTX
1. Introduction to Computer Programming.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Assigned Numbers - 2025 - Bluetooth® Document
Teaching material agriculture food technology
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
cloud_computing_Infrastucture_as_cloud_p
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
NewMind AI Weekly Chronicles - August'25-Week II
Programs and apps: productivity, graphics, security and other tools
Group 1 Presentation -Planning and Decision Making .pptx
SOPHOS-XG Firewall Administrator PPT.pptx
Encapsulation theory and applications.pdf
August Patch Tuesday
Spectroscopy.pptx food analysis technology
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Tartificialntelligence_presentation.pptx
Empathic Computing: Creating Shared Understanding
Machine Learning_overview_presentation.pptx
Univ-Connecticut-ChatGPT-Presentaion.pdf
1. Introduction to Computer Programming.pptx
Encapsulation_ Review paper, used for researhc scholars
Assigned Numbers - 2025 - Bluetooth® Document

Assembly language

  • 2. General purpose registers on the x86 architecture • eax is a 32-bit general-purpose register with two common uses: to store the return value of a function and as a special register for certain calculations. It is technically a volatile register, since the value isn't preserved. Instead, its value is set to the return value of a function before a function returns. eax is also used specifically in certain calculations, such as multiplication and division, as a special register. • ebx is a non-volatile general-purpose register. It has no specific uses, but is often set to a commonly used value (such as 0) throughout a function to speed up calculations. • ecx is a volatile general-purpose register that is occasionally used as a function parameter or as a loop counter. • edx is a volatile general-purpose register that is occasionally used as a function parameter. It is generally used for storing short-term variables within a function.
  • 3. General purpose registers on the x86 architecture • esi is a non-volatile general-purpose register that is often used as a pointer. esi often stores data that is used throughout a function because it doesn't change. • edi is a non-volatile general-purpose register that is often used as a pointer. It is similar to esi, except that it is generally used as a destination for data. • ebp is a non-volatile general-purpose register that has two distinct uses depending on compile settings: it is either the base pointer or a general purpose register. • esp is a special register that stores a pointer to the top of the stack. The value of esp must be the same at the beginning and the end of each function.
  • 5. Special Purpose Registers • eip, or the instruction pointer, is a special-purpose register which stores a pointer to the address of the instruction that is currently executing. • The flags register, where each bit has a specific meaning and they are used to store meta-information about the results of previous operations.
  • 6. The Stack • The stack register, esp, is basically a register that points to an arbitrary location in memory called "the stack". The stack is just a really big section of memory where temporary data can be stored and retrieved. When a function is called, some stack space is allocated to the function, and when a function returns the stack should be in the same state it started in. • The stack always grows downwards, towards lower values. The esp register always points to the lowest value on the stack. Anything below esp is considered free memory that can be overwritten. • The stack stores function parameters, local variables, and the return address of every function.
  • 7. Simple Instructions • Pointers and Dereferencing – eax -- is the value stored in eax – [eax] -- is the value pointed to by eax • Doing Nothing – nop is short for "no operation" and it does nothing. • Moving Data Around – mov can move data between a register and memory, two registers, or a constant to a register. movsx and movzx are special versions of mov which are designed to be used between signed (movsx) and unsigned (movzx) registers of different sizes.
  • 8. Simple Instructions • lea (load effective address) – lea is very similar to mov, except that math can be done on the original value before it is used. The "[" and "]" characters always surround the second parameter, but in this case they do not indicate dereferencing. – lea is generally used for calculating array offsets, since the address of an element of the array can be found with [arraystart + offset*datasize].
  • 9. Simple Instructions: Math and Logic • add, sub: – A register can have either another register, a constant value, or a pointer added to or subtracted from it. • inc, dec: – These instructions simply increment and decrement a register.
  • 10. Simple Instructions: Math and Logic • and, or, xor, neg: – All logical instructions are bitwise. – Bitwise operation: Each bit in the two operands has the operation done between them, and the result is stored in the first one.
  • 11. Simple Instructions: Math and Logic • mul, imul, div, idiv: – Both multiplication and division make use of the 64-bit register edx:eax. • div divides the 64-bit value in edx:eax by the operand, and stores the quotient in eax. The remainder (modulus) is stored in edx. div does both division and modular division, at the same time.
  • 12. Simple Instructions: Math and Logic • cdq: – cdq is generally used immediately before idiv. It stands for "convert double to quad." In other words, convert the 32-bit value in eax to the 64-bit value in edx:eax.
  • 13. Simple Instructions: Math and Logic • shl, shr, sal, sar: shl - shift left, shr - shift right, sal - shift arithmetic left, sar - shift arithmetic right. – These are used to do a binary shift, equivalent to the C operations << and >>. They each take two operations: the register to use, and the number of places to shift the value in the register.
  • 14. Jumping Around • jmp: – jmp, or jump, sends the program execution to the specified address no matter what. • call, ret: – call is similar to jump, except that in addition to sending the program to the specified address, it also saves ("pushes") the address of the executable instruction onto the stack. – ret removes ("pops") the first value off of the stack, and jumps to it. In almost all cases, this value was placed onto the stack by the call instruction. If the stack pointer is at the wrong location, or the saved address was overwritten, ret attempts to jump to an invalid address which usually crashes the program.
  • 15. Jumping Around – ret can also have a parameter. This parameter is added to the stack immediately after ret executes its jump. – The combination of call and ret are used to implement functions.
  • 16. Jumping Around • cmp, test: – cmp, or compare, compares two operands and sets or unsets flags in the flags register based on the result. – Specialized jump commands can check these flags to jump on certain conditions. – test is very similar to cmp, except that it performs a bitwise 'and' operation between the two operands. test is most commonly used to compare a variable to itself to check if it's zero. • jz/je, jnz/jne, jl/jb, jg, jle, jge: – jz and je (which are synonyms) will jump to the address specified if and only if the 'zero' flag is set, which indicates that the two values were equal. In other words, "jump if equal". – jnz and jne (which are also synonyms) will jump to the address specified if and only if the 'zero' flag is not set, which indicates that the two values were not equal. In other words, "jump if different". – jl and jb (which are synonyms) jumps if the first parameter is less than the second. – jg jumps if the first parameter is greater than the second. – jle jumps if the 'less than' or the 'zero' flag is set, so "less than or equal to". – jge jumps if the first is "greater than or equal to" the second.
  • 18. Manipulating the Stack • push, pop: – push decrements the stack pointer by the size of the operand, then saves the operand to the new address. – pop sets the operand to the value on the stack, then increments the stack pointer by the size of the operand.
  • 19. String Instructions • String - a byte or word array: – Operations that can be performed with string instructions: • copy a string into another string • search a string for a particular byte or word • store characters in a string • compare strings of characters alphanumerically • Direction Flag (DF): • one of 8086 processor control flags. • controls the direction of string operations: • DF = 0 => forward (left to right) processing • DF = 1 => backward (right to left) processing • CLD - clears the DF; sets DF = 0 • STD - sets DF = 1
  • 20. String Instructions • Moving (Copying) Strings: • Instruction: MOVS( /B/W/D) dest, src – MOVSB - copies contents of BYTE given by DS:SI into ES:DI – MOVSW - copies contents of WORD given by DS:SI into ES:DI – MOVSD - copies contenst of DOUBLE WORD given by DS:SI into ES:DI • Comparing Strings: • Instruction: CMPS src, dest – The CMPSB(W) instruction can be used to compare a byte(word) in one string (DS:offset in SI) with a byte (word) in another string (ES:offset in DI).
  • 21. String Instructions • Scan String: • Instruction: SCAS <String> – SCAS(/B/W) compares a byte in AL or a word in AX with a byte or word pointed to by DI in ES. • load String: • Instruction: LODS <String> – This instruction copies a byte (word) of string from the location pointed to by SI. • Store String: • Instruction: STOS <String> – The STOS instruction copies a byte (word) from AL (AX) to a memory location stored in [ES:DI].
  • 22. Repetition Prefixes • REP: – REP is a prefix written before one of the string instructions. It is used for repeating an instruction count number of times, where count is stored in the CX register. After every operation the CX register is decremented and the zero flag is tested; the process continues till CX = 0. • REP/REPE/REPNE/REPZ/REPNZ: The REP prefix also has the following variations: – REP: It is the unconditional repeat. It repeats the operation until CX is zero. – REPE or REPZ: It is conditional repeat. It repeats the operation while the zero flag indicates equal/zero. It stops when the ZF indicates not equal/zero or when CX is zero. – REPNE or REPNZ: It is also conditional repeat. It repeats the operation while the zero flag indicates not equal/zero. It stops when the ZF indicates equal/zero or when CX is decremented to zero.
  • 23. DOS Interrupts • Input a character: – MOV AH, 01h – INT 21h • Input a string: – MOV DX, Buffer – MOV AH, 0Ah – INT 21h  Load the desired character into DL & DX, then call the interrupt with function code in AH. • Output a character: – MOV DL, ... – MOV AH, 02h – INT 21h • Output a string: – MOV DX, ... – MOV AH, 09h – INT 21h