Copy a String in Reverse Order Write a program with a loop and indirect addressi
ID: 3864566 • Letter: C
Question
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('#')
This won't work:
INCLUDE Irvine32.inc
source BYTE"This is the source string", 0
target BYTE SIZEOF source DUP('#')
.code
main PROC
mov esi,(OFFSET source)+(SIZEOF source)
mov edi,OFFSET target
mov ecx,SIZEOF source
L1:mov al,[esi]
mov[edi],al
dec esi ;pointer to sorce
inc edi ;pointer to target
loop L1
mov esi,OFFSET target
mov ebx,1
mov ecx, SIZEOF target-1
call Dumpmem
exit
main ENDP
END main
Explanation / Answer
class Coy_Revesre{
public static vaoid main(String args[]){
BufferReader br=new BuffferReader(new InputStreamReader(System.in));
System.out.println("Enter String");//String source="This is the souce string"
String source=br.readLine();
String Copy=source;
System.out.println("Copy string: ");
String revesre="";
int length=source.length();
for(int i=length-1;i>0;i--){
reverse=reverse + charAt(i);
System.out.print("reverse");
}
System.out.println("reverse");
}