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

Copy a String in Reverse Order Write a program with a loop and indirect addressi

ID: 3922991 • 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('#')

and here is what I have got so far

;reverse

INCLUDE IRVINE32.INC

.DATA

SOURCE byte "this is the source string", 0
target BYTE SIZEOF source DUP('#')
.code
main PROC
    Call Clrscr

    mov esi,0
    mov edi,SIZEOF source-TYPE source
    mov ecx,LENGTHOF source
    L1: mov al, source[edi]
    mov target[esi]
    sub edi TYPE source

    loop L1
    exit
    main ENDP
    END main

Explanation / Answer

program with a loop and indirect addressing that copies a string from source to target

MOV SI, source ; Get source address

MOV DI, (target + SIZEOF source) ; Get the ending address for target

LOOP:

MOV AL, [SI] ; Get a byte

MOV [DI], AL ; Store a byte

INC SI ; Move forward one in source

DEC DI ; Move back one in target

CMP AL, 0 ; Have we reached the zero termination?

JNZ LOOP

RET

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