SlideShare a Scribd company logo
DATA TRANSFERS IN ASSEMBLY
SANGRAM KESARI RAY <SHANKAR.RAY030@GMAIL.COM>
DATA TRANSFER INSTRUCTION/S
• OPERAND TYPES
• mnemonic
• mnemonic [dest]
• mnemonic [dest], [src]
• mnemonic [dest], [src1], [src2]
MOV INSTRUCTION
• MOV INSTRUCTION FORMATS
• MOV REGISTER, REGISTER //MOV EAX, EBX
• MOV MEMORY, REGISTER //MOV NUM1, EAX
• MOV REGISTER, MEMORY //MOV EAX, NUM1
• MOV MEMORY, VALUE //MOV NUM1, 10
• MOV REGISTER, VALUE //MOV EAX, 10
MOVZX AND MOVSX INSTRUCTION
• USE THEM WHEN COPYING FROM SMALLER SOURCE TO LARGE DESTINATIONS
• num1 byte 8 //8-bit src
• num2 byte -8 //8-bit src
• eax //32-bit dest
• mov eax, num1 //don’t do this, the register gets filled with incorrect
• movzx eax, num1 //copies a un-signed byte into 16-bit destination
• movsx eax, num2 //copies a signed byte into a 16-bit destination
LAHF AND SAHF INSTRUCTION
LAHF //LOAD LOW-BYTE OF EFLAGS/RFLAGS (SIGN, ZERO, AUXILIARY, PARITY, CARRY) INTO AH REGISTER, AH IS THE HIGH-BYTE OF EAX
SAHF //LOAD AH INTO LOW-BYTE OF EFLAGS/RFLAGS
WHY BOTHER?
SUPPOSE WE WANT TO DO SOMETHING, LOOKING AT EFLAGS FOR 2 INSTRUCTIONS, BUT THIS EFLAGS KEEP CHANGING INSTRUCTION AFTER
INSTRUCTION, WE NEED A WAY TO KEEP A TRACK OF THESE CHANGING EFLAGS.
EXECUTE INSTRUCTION #1 //ELFAGS CHANGED
SAVE EFLAGS INTO AH, STORE AH INTO NUM1
EXECUTE INSTRUCTION #2 //EFLAGS CHANGED
SAVE ELFAGS INTO AH, STORE AH INTO NUM2
IF NUM1 = NUM2
EXECUTE INSTRUCTION #3 // HOPE YOU GOT THE POINT, WHY USE LAHF AND SAHF INSTRUCTIONS?
XCHG INSTRUCTION
• ITS LIKE MOV BUT SWAPS THE VALUES
• XCHG REGISTER, REGISTER //MOV EAX, EBX
• XCHG MEMORY, REGISTER //MOV NUM1, EAX
• XCHG REGISTER, MEMORY //MOV EAX, NUM1
• XCHG MEMORY, VALUE //DOESN’T WORK
• XCHG REGISTER, VALUE //DOESN’T WORK
EFFECTIVE ADDRESSING
• ACCESSING ELEMENTS IN AN ARRY //CONTIGUOUS MEMORY LOCATIONSDF
• MYARRAY DWORD 10, 20, 30
• MOV EAX, MYARRAY //GET 10
• MOV EAX, MYARRAY+1 //GET 20
• MOV EAX, [MYARRAY+1] //GET 20, USE THIS FOR CODE CLARITY WHILE USING ARRAY
I KNOW ASSEMBLY!
DEMO
DATA TRANSFERS – PART 1
https://github.com/shankar-ray/Assembly-Language-Tutorials-for-Windows

More Related Content

Similar to Assembly Language Tutorials for Windows - 04 Data Transfers Part-1

Basic buffer overflow part1
Basic buffer overflow part1Basic buffer overflow part1
Basic buffer overflow part1
Payampardaz
 
Messaging, interoperability and log aggregation - a new framework
Messaging, interoperability and log aggregation - a new frameworkMessaging, interoperability and log aggregation - a new framework
Messaging, interoperability and log aggregation - a new framework
Tomas Doran
 
Stored procedures
Stored proceduresStored procedures
Stored procedures
MuksNoor
 
Alibaba patches in MariaDB
Alibaba patches in MariaDBAlibaba patches in MariaDB
Alibaba patches in MariaDB
Lixun Peng
 
Pipiot - the double-architecture shellcode constructor
Pipiot - the double-architecture shellcode constructorPipiot - the double-architecture shellcode constructor
Pipiot - the double-architecture shellcode constructor
Moshe Zioni
 
Intro to reverse engineering owasp
Intro to reverse engineering   owaspIntro to reverse engineering   owasp
Intro to reverse engineering owasp
Tsvetelin Choranov
 
EC8691-MPMC-PPT.pptx
EC8691-MPMC-PPT.pptxEC8691-MPMC-PPT.pptx
EC8691-MPMC-PPT.pptx
Manikandan813397
 
Qemu Introduction
Qemu IntroductionQemu Introduction
Qemu Introduction
Chiawei Wang
 
Using JavaScript ES2015 (ES6), ES2016, ES2017 in production
Using JavaScript ES2015 (ES6), ES2016, ES2017 in productionUsing JavaScript ES2015 (ES6), ES2016, ES2017 in production
Using JavaScript ES2015 (ES6), ES2016, ES2017 in production
Anže Žnidaršič
 
Redshift deep dive
Redshift deep diveRedshift deep dive
Redshift deep dive
Amazon Web Services LATAM
 
Running & Scaling Large Elasticsearch Clusters
Running & Scaling Large Elasticsearch ClustersRunning & Scaling Large Elasticsearch Clusters
Running & Scaling Large Elasticsearch Clusters
Fred de Villamil
 
Message:Passing - lpw 2012
Message:Passing - lpw 2012Message:Passing - lpw 2012
Message:Passing - lpw 2012
Tomas Doran
 
Where Django Caching Bust at the Seams
Where Django Caching Bust at the SeamsWhere Django Caching Bust at the Seams
Where Django Caching Bust at the Seams
Concentric Sky
 
chapter8.ppt clean code Boundary ppt Coding guide
chapter8.ppt clean code Boundary ppt Coding guidechapter8.ppt clean code Boundary ppt Coding guide
chapter8.ppt clean code Boundary ppt Coding guide
SanjeevSaharan5
 

Similar to Assembly Language Tutorials for Windows - 04 Data Transfers Part-1 (14)

Basic buffer overflow part1
Basic buffer overflow part1Basic buffer overflow part1
Basic buffer overflow part1
 
Messaging, interoperability and log aggregation - a new framework
Messaging, interoperability and log aggregation - a new frameworkMessaging, interoperability and log aggregation - a new framework
Messaging, interoperability and log aggregation - a new framework
 
Stored procedures
Stored proceduresStored procedures
Stored procedures
 
Alibaba patches in MariaDB
Alibaba patches in MariaDBAlibaba patches in MariaDB
Alibaba patches in MariaDB
 
Pipiot - the double-architecture shellcode constructor
Pipiot - the double-architecture shellcode constructorPipiot - the double-architecture shellcode constructor
Pipiot - the double-architecture shellcode constructor
 
Intro to reverse engineering owasp
Intro to reverse engineering   owaspIntro to reverse engineering   owasp
Intro to reverse engineering owasp
 
EC8691-MPMC-PPT.pptx
EC8691-MPMC-PPT.pptxEC8691-MPMC-PPT.pptx
EC8691-MPMC-PPT.pptx
 
Qemu Introduction
Qemu IntroductionQemu Introduction
Qemu Introduction
 
Using JavaScript ES2015 (ES6), ES2016, ES2017 in production
Using JavaScript ES2015 (ES6), ES2016, ES2017 in productionUsing JavaScript ES2015 (ES6), ES2016, ES2017 in production
Using JavaScript ES2015 (ES6), ES2016, ES2017 in production
 
Redshift deep dive
Redshift deep diveRedshift deep dive
Redshift deep dive
 
Running & Scaling Large Elasticsearch Clusters
Running & Scaling Large Elasticsearch ClustersRunning & Scaling Large Elasticsearch Clusters
Running & Scaling Large Elasticsearch Clusters
 
Message:Passing - lpw 2012
Message:Passing - lpw 2012Message:Passing - lpw 2012
Message:Passing - lpw 2012
 
Where Django Caching Bust at the Seams
Where Django Caching Bust at the SeamsWhere Django Caching Bust at the Seams
Where Django Caching Bust at the Seams
 
chapter8.ppt clean code Boundary ppt Coding guide
chapter8.ppt clean code Boundary ppt Coding guidechapter8.ppt clean code Boundary ppt Coding guide
chapter8.ppt clean code Boundary ppt Coding guide
 

Recently uploaded

一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
dakas1
 
Quarter 3 SLRP grade 9.. gshajsbhhaheabh
Quarter 3 SLRP grade 9.. gshajsbhhaheabhQuarter 3 SLRP grade 9.. gshajsbhhaheabh
Quarter 3 SLRP grade 9.. gshajsbhhaheabh
aisafed42
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
Peter Muessig
 
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
kalichargn70th171
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
sjcobrien
 
14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision
ShulagnaSarkar2
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
dakas1
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
Marcin Chrost
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
kalichargn70th171
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
XfilesPro
 
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptxMigration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
ervikas4
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
ICS
 
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
Bert Jan Schrijver
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
ToXSL Technologies
 
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdfBaha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid
 
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
safelyiotech
 

Recently uploaded (20)

一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
 
Quarter 3 SLRP grade 9.. gshajsbhhaheabh
Quarter 3 SLRP grade 9.. gshajsbhhaheabhQuarter 3 SLRP grade 9.. gshajsbhhaheabh
Quarter 3 SLRP grade 9.. gshajsbhhaheabh
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
 
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
 
14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
 
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptxMigration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
 
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
 
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdfBaha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
 
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
 

Assembly Language Tutorials for Windows - 04 Data Transfers Part-1

  • 1. DATA TRANSFERS IN ASSEMBLY SANGRAM KESARI RAY <SHANKAR.RAY030@GMAIL.COM>
  • 2. DATA TRANSFER INSTRUCTION/S • OPERAND TYPES • mnemonic • mnemonic [dest] • mnemonic [dest], [src] • mnemonic [dest], [src1], [src2]
  • 3. MOV INSTRUCTION • MOV INSTRUCTION FORMATS • MOV REGISTER, REGISTER //MOV EAX, EBX • MOV MEMORY, REGISTER //MOV NUM1, EAX • MOV REGISTER, MEMORY //MOV EAX, NUM1 • MOV MEMORY, VALUE //MOV NUM1, 10 • MOV REGISTER, VALUE //MOV EAX, 10
  • 4. MOVZX AND MOVSX INSTRUCTION • USE THEM WHEN COPYING FROM SMALLER SOURCE TO LARGE DESTINATIONS • num1 byte 8 //8-bit src • num2 byte -8 //8-bit src • eax //32-bit dest • mov eax, num1 //don’t do this, the register gets filled with incorrect • movzx eax, num1 //copies a un-signed byte into 16-bit destination • movsx eax, num2 //copies a signed byte into a 16-bit destination
  • 5. LAHF AND SAHF INSTRUCTION LAHF //LOAD LOW-BYTE OF EFLAGS/RFLAGS (SIGN, ZERO, AUXILIARY, PARITY, CARRY) INTO AH REGISTER, AH IS THE HIGH-BYTE OF EAX SAHF //LOAD AH INTO LOW-BYTE OF EFLAGS/RFLAGS WHY BOTHER? SUPPOSE WE WANT TO DO SOMETHING, LOOKING AT EFLAGS FOR 2 INSTRUCTIONS, BUT THIS EFLAGS KEEP CHANGING INSTRUCTION AFTER INSTRUCTION, WE NEED A WAY TO KEEP A TRACK OF THESE CHANGING EFLAGS. EXECUTE INSTRUCTION #1 //ELFAGS CHANGED SAVE EFLAGS INTO AH, STORE AH INTO NUM1 EXECUTE INSTRUCTION #2 //EFLAGS CHANGED SAVE ELFAGS INTO AH, STORE AH INTO NUM2 IF NUM1 = NUM2 EXECUTE INSTRUCTION #3 // HOPE YOU GOT THE POINT, WHY USE LAHF AND SAHF INSTRUCTIONS?
  • 6. XCHG INSTRUCTION • ITS LIKE MOV BUT SWAPS THE VALUES • XCHG REGISTER, REGISTER //MOV EAX, EBX • XCHG MEMORY, REGISTER //MOV NUM1, EAX • XCHG REGISTER, MEMORY //MOV EAX, NUM1 • XCHG MEMORY, VALUE //DOESN’T WORK • XCHG REGISTER, VALUE //DOESN’T WORK
  • 7. EFFECTIVE ADDRESSING • ACCESSING ELEMENTS IN AN ARRY //CONTIGUOUS MEMORY LOCATIONSDF • MYARRAY DWORD 10, 20, 30 • MOV EAX, MYARRAY //GET 10 • MOV EAX, MYARRAY+1 //GET 20 • MOV EAX, [MYARRAY+1] //GET 20, USE THIS FOR CODE CLARITY WHILE USING ARRAY
  • 9. DEMO DATA TRANSFERS – PART 1 https://github.com/shankar-ray/Assembly-Language-Tutorials-for-Windows