Write a program using the LOOP instruction with indirect addressing that copies
ID: 3641626 • Letter: W
Question
Write a program using the LOOP instruction with indirect addressing that copies a string froum source to target, reversing the character order in the process. Use the folling variablessource BYTE "This is the source string", 0
target BYTE SIZEOF source DUP('#')
Insert the following statements immediately after the loop to display the hexadecimal contents of the target string:
mov esi,OFFSET target ;offset of variable
mov ebx, 1 ; byte format
mov ecx, SIZEOF target ; counter
call DumpMem
If your program works correctly, it will display the following sequence of hexadecimal bytes:
67 6E 69 72 74 73 20 65 63 72 75 6F 73 20 65 68
74 20 73 69 2073 69 68 54
Explanation / Answer
you can work it out with C/C++ first, but I'll show you a trick that uses the stack instead of allocating an additional array or writing code to find the end of an array and reading backwards. As you probably already know, the stack works in a 'first in - last out' fashion.
array1 dd 124, 1000, 5000
target_array dd 0,0,0
mov eax, array1 ;push value 124
push eax
mov ebx,array1+4 ;push value 1000
push ebx
mov ecx,array1+8 ;push value 5000
push ecx
mov esi,offset target_array
pop eax ;pop value 5000 off the stack
mov dword ptr ds:[esi], eax ;put popped value in target_array
pop ebx ;pop value 1000 off the stack
mov dword ptr ds:[esi+4], ebx
pop ecx ;pop value 124 off the stack
mov dword ptr ds:[esi+8], ecx
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.