Question: The following 8 0 8 6 assembly program is supposed to concatenate two strings but it doesn't work properly. Why is that? . 5 8

The following 8086 assembly program is supposed to concatenate two strings but it doesn't work properly. Why is that?
.586
.MODEL FLAT
.STACK 4096
INCLUDE io.h
.DATA
Inputstr1 BYTE 100 DUP (?)
Inputstr2 BYTE 100 DUP (?)
Outputstr BYTE 200 DUP (?)
prompt1 BYTE "Enter the first string: ",0
prompt2 BYTE "Enter the second string: ",0
displayLbl BYTE "Concatenated string: ",0
.CODE
_MainProc PROC
input prompt1, Inputstr1,100
input prompt2, Inputstr2,100
; Copy the first string to Outputstr
mov esi, OFFSET Inputstr1
mov edi, OFFSET Outputstr
mov ecx, 100
cld
rep movsb
; Find the end of the first string
mov ebx, edi ; Save the current position in ebx
lea esi, OFFSET Inputstr2
add edi, 100 ; Move edi to the end of the copied string
mov ecx, 100
repne scasb ; Find the null terminator
; Copy the second string to Outputstr
mov esi, OFFSET Inputstr2
mov edi, ebx ; Restore the saved position
sub edi, 1 ; Move edi back one byte to overwrite the null terminator
mov ecx, 100
cld
rep movsb
output displayLbl, Outputstr
mov eax, 0
ret
_MainProc ENDP
END

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!