English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 06 July 2013, 21:21   #1
christopherpm
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?
christopherpm is offline  
Old 06 July 2013, 21:24   #2
JonB
Registered User
 
Join Date: Apr 2013
Location: Sussex
Posts: 42
Which language?
JonB is offline  
Old 06 July 2013, 21:56   #3
christopherpm
Registered User
 
Join Date: Feb 2013
Location: Fort William
Posts: 122
Sorry - assembler for 68000 using Devpac 3
christopherpm is offline  
Old 06 July 2013, 22:03   #4
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 6,985
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?
thomas is offline  
Old 06 July 2013, 22:10   #5
christopherpm
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"
christopherpm is offline  
Old 07 July 2013, 00:14   #6
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 6,985
Why do you want to concatenate the strings? You can first write "Data save to " and then write filename.
thomas is offline  
Old 07 July 2013, 01:01   #7
DrCinicus
Registered User
 
Join Date: Oct 2008
Location: Assemini/Italy
Age: 51
Posts: 23
Quote:
Originally Posted by christopherpm View Post
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"
To append the date in a "fixed" format ddmm

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
The final filename will be "myfilename0707"

Bye
Fabio
DrCinicus is offline  
Old 08 July 2013, 18:05   #8
Photon
Moderator
 
Photon's Avatar
 
Join Date: Nov 2004
Location: Eksjö / Sweden
Posts: 5,602
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.
Photon is offline  
Old 09 July 2013, 11:43   #9
hooverphonique
ex. demoscener "Bigmama"
 
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
well, since he wants the concatenated parts in a filename, outputting bit by bit won't work, guys..
hooverphonique is offline  
Old 09 July 2013, 11:46   #10
christopherpm
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.
christopherpm is offline  
Old 10 July 2013, 19:43   #11
Photon
Moderator
 
Photon's Avatar
 
Join Date: Nov 2004
Location: Eksjö / Sweden
Posts: 5,602
Quote:
Originally Posted by hooverphonique View Post
well, since he wants the concatenated parts in a filename, outputting bit by bit won't work, guys..
Well, the original question was how to concatenate strings, and I did supply the correct pseudocode.

Quote:
Originally Posted by christopherpm View Post
Thanks - I used Fabio's solution and it worked well for what I need.
Great As per my generic concatenation example, it's a matter of declaring byte storage and just copying the character bytes.

(If you come from C, the address registers are used similarly to char* (byte array pointers).)
Photon is offline  
 


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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 16:19.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.13850 seconds with 13 queries