I am working on a program, and I can't figure out what I'm doing wrong. Any help would be appreciated. Here is what I have to do:


Write a procedure named St_concat that concatenates a source string to the end of a target string. Sufficient space must exist in the target string to accommodate the new characters. Pass pointers to the source and target strings. Here is a sample call:

.data
targetStr BYTE "ABCDE",10 DUP(0)
sourceStr BYTE "FGH",0
.code
INVOKE Str_concat, ADDR targetStr, ADDR sourceStr

Here is what I have so far:

TITLE String Concatenate                (StrConcat.asm)

; This program concatenates a source
; string to the end of a target string.


INCLUDE Irvine32.inc
INCLUDE Bsearch.inc

ARRAY_SIZE = 1

.data
array DWORD ARRAY_SIZE DUP(?)
targetStr BYTE "ABCDE",10 DUP(0)
sourceStr BYTE "FGH",0

LOWVAL = targetStr
HIGHVAL = sourceStr


.code
main PROC
; Fill an array with random signed integers
INVOKE FillArray, ADDR array, ARRAY_SIZE, LOWVAL, HIGHVAL

; Display the array
INVOKE PrintArray, ADDR array, ARRAY_SIZE
	call WaitMsg

; Perform a bubble sort and redisplay the array
INVOKE BubbleSort, ADDR array, ARRAY_SIZE
INVOKE PrintArray, ADDR array, ARRAY_SIZE

	call Str_concat

	exit
main ENDP

;------------------------------------------------------------
BubbleSort PROC USES eax ecx esi,
	pArray:PTR DWORD,		; pointer to array
	Count:DWORD			; array size
;
; Sort an array of 32-bit signed integers in ascending
; order, using the bubble sort algorithm.
; Receives: pointer to array, array size
; Returns: nothing
;------------------------------------------------------------

	mov ecx,Count
	dec ecx				; decrement count by 1

L1:	push ecx			; save outer loop count
	mov esi,pArray			; point to first value

L2:	mov eax,[esi]			; get array value
	cmp [esi+4],eax			; compare a pair of values
	jge L3				; if [ESI] <= [EDI], no exchange
	xchg eax,[esi+4]		; exchange the pair
	mov [esi],eax

L3:	add esi,4			; move both pointers forward
	loop L2				; inner loop

	pop ecx				; retrieve outer loop count
	loop L1				; else repeat outer loop

L4: 	ret

BubbleSort ENDP

;------------------------------------------------------------
FillArray PROC USES eax edi ecx edx,
	pArray:PTR DWORD,		; pointer to array
	Count:DWORD,			; number of elements
	A:SDWORD,	       		; ABCDE
	B:SDWORD   			; FGH
;
; Fills an array with a random sequence of 32-bit signed
; integers between LowerRange and (UpperRange - 1).
; Returns: nothing
;------------------------------------------------------------
	mov edi,pArray			; EDI points to the array
	mov ecx,Count			; loop counter
	mov edx,A
	sub edx,B			; EDX = absolute range (0..n)

L1:	mov eax,edx			; get absolute range
	add eax,B			; bias the result
	stosd				; store EAX into [edi]

	mov edx,OFFSET targetStr
	call WriteString

	loop L1

	ret

	call Str_concat
FillArray ENDP

;------------------------------------------------------------
PrintArray PROC USES eax ecx edx esi,
	pArray:PTR DWORD,		; pointer to array
	Count:DWORD			; number of elements
;
; Writes an array of 32-bit signed decimal integers to
; standard output, separated by commas
; Receives: pointer to array, array size
; Returns: nothing
;------------------------------------------------------------
.data
comma BYTE ", ",0

.code
	mov esi,pArray
	mov ecx,Count
	cld				; direction = forward

L1: 	lodsd				; load [ESI] into EAX

	loop L1

	call Crlf
	ret
PrintArray ENDP

;------------------------------------------------------------
Str_concat PROC USES eax ecx esi,
	pArray:PTR DWORD,		; pointer to array
	Count:DWORD			; array size
;
; Sort an array of 32-bit signed integers in ascending
; order, using the bubble sort algorithm.
; Receives: pointer to array, array size
; Returns: nothing
;------------------------------------------------------------
.code
INVOKE Str_concat, ADDR targetStr, ADDR sourceStr

	mov ecx,Count
	dec ecx				; decrement count by 1

L1: 	push ecx			; save outer loop count
	mov esi,pArray			; point to first value

L2:	mov eax,[esi]			; get array value
	cmp [esi+4],eax			; compare a pair of values
	jge L3				; if [ESI] <= [EDI], no exchange
	xchg eax,[esi+4]		; exchange pair
	mov [esi],eax

	mov edx,OFFSET sourceStr
	call WriteString


L3:	add esi,4			; move both pointers forward
	loop L2				; inner loop

	pop ecx				; retrieve outer loop count
	loop L1				; else repeat outer loop

L4:	ret

Str_concat ENDP

END main

Nevermind. I came up with the solution.

If anybody is interested, here is what I got for my answer:

TITLE String Concatenate                (StrConcat.asm)

; This program concatenates a source
; string to the end of a target string.


INCLUDE Irvine32.inc
INCLUDE Bsearch.inc

STRING_SIZE = 10

	
Str_concat PROTO,
	source:PTR BYTE, 		; source string
	target:PTR BYTE			; target string


.data
targetStr BYTE "ABCDE",10 DUP(0)
sourceStr BYTE "FGH",0

.code
main PROC

; Display
mov edx,OFFSET targetStr
call WriteString

call Crlf

call WaitMsg

mov eax,LENGTHOF sourceStr

INVOKE Str_concat, ADDR sourceStr, ADDR targetStr

mov edx,OFFSET targetStr
call WriteString
	
call Crlf

	exit
main ENDP

;------------------------------------------------------------
FillString PROC USES eax edi ecx edx,
	pString:PTR DWORD,		; pointer to array
	Count:DWORD,			; number of elements
	string_1:SDWORD,	       	; ABCDE
	string_2:SDWORD   		; FGH
;
; Fills the string with "ABCDE", then concatenates, "FGH" onto it.
; Returns: nothing
;------------------------------------------------------------
	mov edi,pString			; EDI points to the string
	mov ecx,Count			; loop counter
	mov edx,string_1
	sub edx,string_2		; EDX = absolute range (0..n)

L1:	mov eax,edx			; get absolute range
	add eax,string_2		; bias the result
	stosd				; store EAX into [edi]

	loop L1

	ret

FillString ENDP
;------------------------------------------------------------
Str_concat PROC USES eax ecx esi edi,
 	source:PTR BYTE, 		; source string
 	target:PTR BYTE			; target string
;------------------------------------------------------------
mov ecx,eax				; EAX = length source

mov esi,source
mov edi,target
add edi,5
cld					; direction = forward
rep movsb				; copy the string

ret

Str_concat ENDP

END main

;Take a look at this one too:

str_cat proc strBase:DWORD, strAdd:DWORD
			mov edi, strBase
			mov al, 0
			repne scasb
			dec edi
			mov esi, strAdd
			@@:
				mov al, [esi]
				mov [edi], al
				inc esi
				inc edi
				test al, al
				jnz @B
				ret
		str_cat endp

;an example is in attach.

why do you need the FillString procedure? you not even using it. Also Why include Bsearch.inc and String_Size?

This question has already been answered. Start a new discussion instead.