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