| | |
String Concatenation Help
Please support our Assembly advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
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:
Here is what I have so far:
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:
Assembly Syntax (Toggle Plain Text)
.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:
If anybody is interested, here is what I got for my answer:
Assembly Syntax (Toggle Plain Text)
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
•
•
Join Date: Nov 2008
Posts: 23
Reputation:
Solved Threads: 2
;Take a look at this one too:
;an example is in attach.
Assembly Syntax (Toggle Plain Text)
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
Last edited by low_coder; Nov 26th, 2008 at 8:19 am. Reason: wrong attach.
![]() |
Similar Threads
- string concatenation in loop (Java)
- concatenate words without using STRING.H (C++)
- Odd string concatenation behavior? (Perl)
- hi.. string compare (Java)
- first cannot conver std::string to const char, now runtime error! (C++)
- Trying to overload + for class to add to string 'is illegal' (C)
- Using string variables in a label or text box? (VB.NET)
Other Threads in the Assembly Forum
- Previous Thread: NEED HELP! (hex to decimal output)
- Next Thread: Simple Assembly Copy Program using int 21h
| Thread Tools | Search this Thread |
Tag cloud for Assembly





