Question: Suppose a program has the string COMSC 2 6 0 stored in source. The goal of the program is to store the reversed string,

Suppose a program has the string "COMSC 260" stored in source. The goal of the program is to store the reversed string, "062 CSMOC" in target. Part of the program is as follows:
.data
source BYTE "COMSC 260",0
target BYTE SIZEOF source DUP(?)
.code
main PROC
mov ecx,SIZEOF source-1
L1:
mov al,[esi]
mov [edi], al
dec esi
inc edi
loop L1
mov BYTE PTR [edi],0
For this program to work correctly, esi and edi must both be initialized correctly. Which of the options below correctly initializes both registers?
NOTE: The source string ends with a null terminator (0). After the program finishes running, the target string will also end with a null terminator (0).
A)
mov esi, OFFSET [target -1]
mov edi, OFFSET [source + SIZEOF source +1]
B)
mov esi, OFFSET [target -1]
mov edi, OFFSET [source + SIZEOF source]
C)
mov esi, OFFSET [target -2]
mov edi, OFFSET [source + SIZEOF source]
D)
mov esi, OFFSET [target -2]
mov edi, OFFSET [source + SIZEOF source +1]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!