Question: Assembly Language for x86 Processors, Copying a string backwards: Write a program using the LOOP instruction with indirect operands (not indexed operands) that copies a
Assembly Language for x86 Processors,
Copying a string backwards:
Write a program using the LOOP instruction with indirect operands (not indexed operands) that copies a string from source to target, reversing the character order in the process. Don't use PUSH/POP at this time. Referring to the CopyStr.asm, your algorithm can be like this:
Point ESI to the end of the source string
Point EDI to the beginning of the target string
Initialize the loop counter ECX and start a loop
Get a character from source
Store it in the target
Update ESI and EDI
Make a terminator at the end of the target in your code logic. Don't rely on the target initialization
Call WriteString to output the two strings similar to this:
Original: This is the source string Reversed: gnirts ecruos eht si sihT |
And here is my code:
INCLUDE Irvine32.inc WriteString PROTO
.data message BYTE "This is the source string",0 str1 BYTE "Original: ",0 str2 BYTE "Reverse: ",0 target BYTE 25 DUP ('#')
.code main PROC mov edx, OFFSET str1 call WriteString mov edx, OFFSET message call WriteString call Crlf mov esi, 0 mov edi, LENGTHOF message - 2 mov ecx, SIZEOF message
L1: mov al, message[esi] mov target[edi], al inc esi dec edi loop L1 mov edx, OFFSET str2 call WriteString mov edx, OFFSET target call WriteString call Crlf exit main ENDP END main
So far my code works, but I need to fix it using indirect operands.
Thank you in advance.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
