06 July 2013, 21:21 | #1 |
Registered User
Join Date: Feb 2013
Location: Fort William
Posts: 122
|
Concatenating strings?
It's been 20 years since I last wrote an Amiga program, but last week I came across some of my old source code. I typed the program in and compiled it, and as I was doing so, the memories came flooding back, and the code still made sense.
However, one thing I cannot for the life of me remember how to do is concatenate 2 or more text strings. Can anyone remind me? |
06 July 2013, 21:24 | #2 |
Registered User
Join Date: Apr 2013
Location: Sussex
Posts: 42
|
Which language?
|
06 July 2013, 21:56 | #3 |
Registered User
Join Date: Feb 2013
Location: Fort William
Posts: 122
|
Sorry - assembler for 68000 using Devpac 3
|
06 July 2013, 22:03 | #4 |
Registered User
Join Date: Jan 2002
Location: Germany
Posts: 7,028
|
Please define "string". Fixed-length string? C-style string with 0-byte at the end? BCPL-style string with length-byte in the beginning? Something else?
And how are the strings stored? Do you want to copy the second string to the end of the first string, given that the first string has enough free space behind it? Or do you want to copy both strings into a new buffer which is known to be large enough? Or do you want to allocate a new buffer and eventually free the two old buffers (given that they have been allocated earlier)? If you want to free buffers, where did you store the size of the buffers? |
06 July 2013, 22:10 | #5 |
Registered User
Join Date: Feb 2013
Location: Fort William
Posts: 122
|
I am saving the contents of a buffer to a file. I have a base filename, and I want to append the day and month (in numerical format) to the filename. Once my buffer has been written, I want to display a message which reads:-
Data saved to <filename> At the moment, I have declared my filename as such:- filename: dc.b "myfilename" |
07 July 2013, 00:14 | #6 |
Registered User
Join Date: Jan 2002
Location: Germany
Posts: 7,028
|
Why do you want to concatenate the strings? You can first write "Data save to " and then write filename.
|
07 July 2013, 01:01 | #7 | |
Registered User
Join Date: Oct 2008
Location: Assemini/Italy
Age: 51
Posts: 23
|
Quote:
Code:
AddDate: lea day(pc),a2 move.b #'0',(a2) move.b #'7',1(a2) lea month(pc),a2 move.b #'0',(a2) move.b #'7',1(a2) rts Filename: dc.b 'myfilename' day: dc.b 'dd' month: dc.b 'mm' dc.b 0 ' NULL termination Bye Fabio |
|
08 July 2013, 18:05 | #8 |
Moderator
Join Date: Nov 2004
Location: Eksjö / Sweden
Posts: 5,658
|
Thomas is correct, usually strings are concatenated as they are being output to the destination, such as the shell window or a file. This also allows you to insert some good logic, conditionals and parsing in between output of "snippets", so it's more flexible and smart.
If you need a function for some reason, it's quite simple: If a0-a2 points to string 1, string 2, and the concatenated result buffer, all 0-terminated, then a concatenation function can be written with loops: move.b (a0)+,(a2)+ until zero, then subq #1,a2, and move.b (a1)+,(a2)+ until zero. |
09 July 2013, 11:43 | #9 |
ex. demoscener "Bigmama"
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,643
|
well, since he wants the concatenated parts in a filename, outputting bit by bit won't work, guys..
|
09 July 2013, 11:46 | #10 |
Registered User
Join Date: Feb 2013
Location: Fort William
Posts: 122
|
Thanks - I used Fabio's solution and it worked well for what I need.
|
10 July 2013, 19:43 | #11 | ||
Moderator
Join Date: Nov 2004
Location: Eksjö / Sweden
Posts: 5,658
|
Quote:
Quote:
(If you come from C, the address registers are used similarly to char* (byte array pointers).) |
||
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[FS-UAE] Extract strings from FS-UAE memory | starwindz | support.FS-UAE | 2 | 06 August 2012 19:49 |
Strange debugger strings for DFx.... | Alexco | support.WinUAE | 1 | 27 May 2009 22:21 |
|
|