SlideShare a Scribd company logo
1 of 2
Download to read offline
Copy a String in Reverse Order
Write a program with a loop and indirect addressing that copies a string from source to target,
reversing the character order in the process. Use the following variables:
source BYTE "This is the source string",0
target BYTE SIZEOF source DUP('#')
and here is what I have got so far
;reverse
INCLUDE IRVINE32.INC
.DATA
SOURCE byte "this is the source string", 0
target BYTE SIZEOF source DUP('#')
.code
main PROC
Call Clrscr
mov esi,0
mov edi,SIZEOF source-TYPE source
mov ecx,LENGTHOF source
L1: mov al, source[edi]
mov target[esi]
sub edi TYPE source
loop L1
exit
main ENDP
END main
Solution
program with a loop and indirect addressing that copies a string from source to target
MOV SI, source ; Get source address
MOV DI, (target + SIZEOF source) ; Get the ending address for target
LOOP:
MOV AL, [SI] ; Get a byte
MOV [DI], AL ; Store a byte
INC SI ; Move forward one in source
DEC DI ; Move back one in target
CMP AL, 0 ; Have we reached the zero termination?
JNZ LOOP
RET

More Related Content

Similar to Copy a String in Reverse Order Write a program with a loop and ind.pdf

Cs1123 3 c++ overview
Cs1123 3 c++ overviewCs1123 3 c++ overview
Cs1123 3 c++ overview
TAlha MAlik
 
cmp104 lec 8
cmp104 lec 8cmp104 lec 8
cmp104 lec 8
kapil078
 
Embedded system (Chapter 2) part 2
Embedded system (Chapter 2) part 2Embedded system (Chapter 2) part 2
Embedded system (Chapter 2) part 2
Ikhwan_Fakrudin
 

Similar to Copy a String in Reverse Order Write a program with a loop and ind.pdf (20)

Hot Code Replacement - Alexei Sholik
Hot Code Replacement - Alexei SholikHot Code Replacement - Alexei Sholik
Hot Code Replacement - Alexei Sholik
 
NASM Introduction.pptx
NASM Introduction.pptxNASM Introduction.pptx
NASM Introduction.pptx
 
Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programming
 
C++Basics.pdf
C++Basics.pdfC++Basics.pdf
C++Basics.pdf
 
C standard library functions
C standard library functionsC standard library functions
C standard library functions
 
Devry cis 170 c i lab 5 of 7 arrays and strings
Devry cis 170 c i lab 5 of 7 arrays and stringsDevry cis 170 c i lab 5 of 7 arrays and strings
Devry cis 170 c i lab 5 of 7 arrays and strings
 
Dive into exploit development
Dive into exploit developmentDive into exploit development
Dive into exploit development
 
Cs1123 3 c++ overview
Cs1123 3 c++ overviewCs1123 3 c++ overview
Cs1123 3 c++ overview
 
cmp104 lec 8
cmp104 lec 8cmp104 lec 8
cmp104 lec 8
 
instead of referencing the data variable called spaces in the display.pdf
instead of referencing the data variable called spaces in the display.pdfinstead of referencing the data variable called spaces in the display.pdf
instead of referencing the data variable called spaces in the display.pdf
 
C# What's next? (7.x and 8.0)
C# What's next? (7.x and 8.0)C# What's next? (7.x and 8.0)
C# What's next? (7.x and 8.0)
 
Bidirectional Programming for Self-adaptive Software
Bidirectional Programming for Self-adaptive SoftwareBidirectional Programming for Self-adaptive Software
Bidirectional Programming for Self-adaptive Software
 
270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt
 
Survey of programming language getting started in C
Survey of programming language getting started in CSurvey of programming language getting started in C
Survey of programming language getting started in C
 
270 1 c_intro_up_to_functions
270 1 c_intro_up_to_functions270 1 c_intro_up_to_functions
270 1 c_intro_up_to_functions
 
270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt
 
Fake News and Their Detection
Fake News and Their DetectionFake News and Their Detection
Fake News and Their Detection
 
OOPS using C++
OOPS using C++OOPS using C++
OOPS using C++
 
C++ Basics introduction to typecasting Webinar Slides 1
C++ Basics introduction to typecasting Webinar Slides 1C++ Basics introduction to typecasting Webinar Slides 1
C++ Basics introduction to typecasting Webinar Slides 1
 
Embedded system (Chapter 2) part 2
Embedded system (Chapter 2) part 2Embedded system (Chapter 2) part 2
Embedded system (Chapter 2) part 2
 

More from arihantsherwani

The age of the Earth is estimated from the amount of uranium isotope .pdf
The age of the Earth is estimated from the amount of uranium isotope .pdfThe age of the Earth is estimated from the amount of uranium isotope .pdf
The age of the Earth is estimated from the amount of uranium isotope .pdf
arihantsherwani
 
Match the terms to the definitions provided.Question 2 optionsd.pdf
Match the terms to the definitions provided.Question 2 optionsd.pdfMatch the terms to the definitions provided.Question 2 optionsd.pdf
Match the terms to the definitions provided.Question 2 optionsd.pdf
arihantsherwani
 
Sand, Mell, and Rand are partners who share incomes and losses in a .pdf
Sand, Mell, and Rand are partners who share incomes and losses in a .pdfSand, Mell, and Rand are partners who share incomes and losses in a .pdf
Sand, Mell, and Rand are partners who share incomes and losses in a .pdf
arihantsherwani
 
PLEASE ANSWER ALL THE QUESTIONES BELOW AS DETAILED AS POSSIBLE. THAN.pdf
PLEASE ANSWER ALL THE QUESTIONES BELOW AS DETAILED AS POSSIBLE. THAN.pdfPLEASE ANSWER ALL THE QUESTIONES BELOW AS DETAILED AS POSSIBLE. THAN.pdf
PLEASE ANSWER ALL THE QUESTIONES BELOW AS DETAILED AS POSSIBLE. THAN.pdf
arihantsherwani
 
Invertebrates colonized terrestrial environments independently of ve.pdf
Invertebrates colonized terrestrial environments independently of ve.pdfInvertebrates colonized terrestrial environments independently of ve.pdf
Invertebrates colonized terrestrial environments independently of ve.pdf
arihantsherwani
 
Discuss the outcomes and challenges surrounding shortages in various.pdf
Discuss the outcomes and challenges surrounding shortages in various.pdfDiscuss the outcomes and challenges surrounding shortages in various.pdf
Discuss the outcomes and challenges surrounding shortages in various.pdf
arihantsherwani
 
Create a C program that implements The Game of Life cellular auto.pdf
Create a C program that implements The Game of Life cellular auto.pdfCreate a C program that implements The Game of Life cellular auto.pdf
Create a C program that implements The Game of Life cellular auto.pdf
arihantsherwani
 
Case Study 1Hotel worker Danny Ruiz was living with his wife and f.pdf
Case Study 1Hotel worker Danny Ruiz was living with his wife and f.pdfCase Study 1Hotel worker Danny Ruiz was living with his wife and f.pdf
Case Study 1Hotel worker Danny Ruiz was living with his wife and f.pdf
arihantsherwani
 
A 7 year old female with a history of previous UTI’s suddenly develo.pdf
A 7 year old female with a history of previous UTI’s suddenly develo.pdfA 7 year old female with a history of previous UTI’s suddenly develo.pdf
A 7 year old female with a history of previous UTI’s suddenly develo.pdf
arihantsherwani
 
5. Toxco, Inc. emits a noxious gaseous substance as a waste product o.pdf
5. Toxco, Inc. emits a noxious gaseous substance as a waste product o.pdf5. Toxco, Inc. emits a noxious gaseous substance as a waste product o.pdf
5. Toxco, Inc. emits a noxious gaseous substance as a waste product o.pdf
arihantsherwani
 

More from arihantsherwani (20)

The age of the Earth is estimated from the amount of uranium isotope .pdf
The age of the Earth is estimated from the amount of uranium isotope .pdfThe age of the Earth is estimated from the amount of uranium isotope .pdf
The age of the Earth is estimated from the amount of uranium isotope .pdf
 
Suppose Michael creates an RSA cryptosystem with a very large mod­ulu.pdf
Suppose Michael creates an RSA cryptosystem with a very large mod­ulu.pdfSuppose Michael creates an RSA cryptosystem with a very large mod­ulu.pdf
Suppose Michael creates an RSA cryptosystem with a very large mod­ulu.pdf
 
Match the terms to the definitions provided.Question 2 optionsd.pdf
Match the terms to the definitions provided.Question 2 optionsd.pdfMatch the terms to the definitions provided.Question 2 optionsd.pdf
Match the terms to the definitions provided.Question 2 optionsd.pdf
 
Simple linear regression and multiple regression are both based on t.pdf
Simple linear regression and multiple regression are both based on t.pdfSimple linear regression and multiple regression are both based on t.pdf
Simple linear regression and multiple regression are both based on t.pdf
 
Sand, Mell, and Rand are partners who share incomes and losses in a .pdf
Sand, Mell, and Rand are partners who share incomes and losses in a .pdfSand, Mell, and Rand are partners who share incomes and losses in a .pdf
Sand, Mell, and Rand are partners who share incomes and losses in a .pdf
 
PLEASE ANSWER ALL THE QUESTIONES BELOW AS DETAILED AS POSSIBLE. THAN.pdf
PLEASE ANSWER ALL THE QUESTIONES BELOW AS DETAILED AS POSSIBLE. THAN.pdfPLEASE ANSWER ALL THE QUESTIONES BELOW AS DETAILED AS POSSIBLE. THAN.pdf
PLEASE ANSWER ALL THE QUESTIONES BELOW AS DETAILED AS POSSIBLE. THAN.pdf
 
Livingstone is a marble freak and loves to paly at school. During th.pdf
Livingstone is a marble freak and loves to paly at school. During th.pdfLivingstone is a marble freak and loves to paly at school. During th.pdf
Livingstone is a marble freak and loves to paly at school. During th.pdf
 
Invertebrates colonized terrestrial environments independently of ve.pdf
Invertebrates colonized terrestrial environments independently of ve.pdfInvertebrates colonized terrestrial environments independently of ve.pdf
Invertebrates colonized terrestrial environments independently of ve.pdf
 
Is there a similarity transformation that maps Delta ABC to Delta DBF.pdf
Is there a similarity transformation that maps Delta ABC to Delta DBF.pdfIs there a similarity transformation that maps Delta ABC to Delta DBF.pdf
Is there a similarity transformation that maps Delta ABC to Delta DBF.pdf
 
Felix and Janet Green live in Swarthmore, PA. Janets father, Larry,.pdf
Felix and Janet Green live in Swarthmore, PA. Janets father, Larry,.pdfFelix and Janet Green live in Swarthmore, PA. Janets father, Larry,.pdf
Felix and Janet Green live in Swarthmore, PA. Janets father, Larry,.pdf
 
Do the leaves of all plants have an abscission layer If not, what h.pdf
Do the leaves of all plants have an abscission layer If not, what h.pdfDo the leaves of all plants have an abscission layer If not, what h.pdf
Do the leaves of all plants have an abscission layer If not, what h.pdf
 
Discuss the outcomes and challenges surrounding shortages in various.pdf
Discuss the outcomes and challenges surrounding shortages in various.pdfDiscuss the outcomes and challenges surrounding shortages in various.pdf
Discuss the outcomes and challenges surrounding shortages in various.pdf
 
Create a C program that implements The Game of Life cellular auto.pdf
Create a C program that implements The Game of Life cellular auto.pdfCreate a C program that implements The Game of Life cellular auto.pdf
Create a C program that implements The Game of Life cellular auto.pdf
 
Compare and contrast prokaryotic cells and eukaryotic cells. Compare.pdf
Compare and contrast prokaryotic cells and eukaryotic cells.  Compare.pdfCompare and contrast prokaryotic cells and eukaryotic cells.  Compare.pdf
Compare and contrast prokaryotic cells and eukaryotic cells. Compare.pdf
 
Case Study 1Hotel worker Danny Ruiz was living with his wife and f.pdf
Case Study 1Hotel worker Danny Ruiz was living with his wife and f.pdfCase Study 1Hotel worker Danny Ruiz was living with his wife and f.pdf
Case Study 1Hotel worker Danny Ruiz was living with his wife and f.pdf
 
Assignment Submission Assignment, you submit answers by question by .pdf
Assignment Submission  Assignment, you submit answers by question by .pdfAssignment Submission  Assignment, you submit answers by question by .pdf
Assignment Submission Assignment, you submit answers by question by .pdf
 
A linear dynamical system can be created for two masses connected by.pdf
A linear dynamical system can be created for two masses connected by.pdfA linear dynamical system can be created for two masses connected by.pdf
A linear dynamical system can be created for two masses connected by.pdf
 
A 7 year old female with a history of previous UTI’s suddenly develo.pdf
A 7 year old female with a history of previous UTI’s suddenly develo.pdfA 7 year old female with a history of previous UTI’s suddenly develo.pdf
A 7 year old female with a history of previous UTI’s suddenly develo.pdf
 
5. Toxco, Inc. emits a noxious gaseous substance as a waste product o.pdf
5. Toxco, Inc. emits a noxious gaseous substance as a waste product o.pdf5. Toxco, Inc. emits a noxious gaseous substance as a waste product o.pdf
5. Toxco, Inc. emits a noxious gaseous substance as a waste product o.pdf
 
21. Two fair coins are tossed. Let E be the event not more than one h.pdf
21. Two fair coins are tossed. Let E be the event not more than one h.pdf21. Two fair coins are tossed. Let E be the event not more than one h.pdf
21. Two fair coins are tossed. Let E be the event not more than one h.pdf
 

Recently uploaded

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 

Copy a String in Reverse Order Write a program with a loop and ind.pdf

  • 1. Copy a String in Reverse Order Write a program with a loop and indirect addressing that copies a string from source to target, reversing the character order in the process. Use the following variables: source BYTE "This is the source string",0 target BYTE SIZEOF source DUP('#') and here is what I have got so far ;reverse INCLUDE IRVINE32.INC .DATA SOURCE byte "this is the source string", 0 target BYTE SIZEOF source DUP('#') .code main PROC Call Clrscr mov esi,0 mov edi,SIZEOF source-TYPE source mov ecx,LENGTHOF source L1: mov al, source[edi] mov target[esi] sub edi TYPE source loop L1 exit main ENDP END main Solution program with a loop and indirect addressing that copies a string from source to target MOV SI, source ; Get source address MOV DI, (target + SIZEOF source) ; Get the ending address for target LOOP: MOV AL, [SI] ; Get a byte MOV [DI], AL ; Store a byte INC SI ; Move forward one in source DEC DI ; Move back one in target
  • 2. CMP AL, 0 ; Have we reached the zero termination? JNZ LOOP RET