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

Computer Science: Assembly Language for x86 Processors VS 2017 [C++] Copy a Stri

ID: 3869676 • Letter: C

Question

Computer Science: Assembly Language for x86 Processors

VS 2017 [C++]

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

a) Point ESI to the end of the source string

b) Point EDI to the beginning of the target string

c) Initialize the loop counter ECX and start a loop

- Get a character from source

- Store it in the target

- Update ESI and EDI

d) Make a terminator at the end of the target in your code logic. Don't rely on the target initialization

e) Call WriteString to output the two strings similar to this:

Alternative solution: A little challenging while more efficient is in-place reversing a string: what if using xchg?

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

Explanation / Answer

DATA SEGMENT
STR1 DB 'This is the source string'
LEN EQU $-STR1
STR2 DB 30 DUP(0)
DATA SEGMENT ENDS
CODE SEGMENT
# CS:CODE,DS:DATA,ES:DATA
START: MOV AX,DATA
MOV DS,AX
MOV ES,AX
LEA SI,STR1
LEA DI,STR2+LEN-1
MOV CX,LEN
MYLOOP: CLD
LODSB
STD
STOSB
LOOP MYLOOP
MOV AH,4CH
INT 21H

END START

CODE SEGMENT ENDS

STR1 represents the original string.

The code after execution places the reverse string in the data segment.

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