Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assembly Language for x86 Processors, Copying a string backwards: Write a progra

ID: 3873718 • Letter: A

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 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:

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.

  Original: This is the source string  Reversed: gnirts ecruos eht si sihT  

Explanation / Answer

x86 assembly language is a family of backward-compatible assembly languages, which provide some level of compatibility all the way back to the intel 8008 introduced in April 1972. x86 assembly language are used to produce object code for the x86 class of processors. Like all assembly languages, it uses short mnemonics to represent the fundamental instructions that the CPU in a computer can understand and follow. Compilers sometimes produce assembly code as an intermediate step when translating a high level program into machine code. Regarded as a programmimg language, assembly coding is machine-specific and low level. Assembly languages are more typically used for detailed and time-critical applications such as small real-time embedded systems or operating system kernels and device drivers.

INCLUDE Irvine32.inc WriteString PROTO

.data source BYTE "This is the source string",0 target BYTE SIZEOF source DUP('#')

.code main PROC mov esi,0 mov edi,LENGTHOF source - 2 mov ecx,SIZEOF source L1: mov al,source[esi] mov target[edi],al inc esi dec edi loop L1 mov edx, OFFSET target call WriteString

exit main ENDP END main

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote