Groups | Search | Server Info | Login | Register


Groups > comp.sys.acorn.programmer > #6627

Re: Name of a program

From Theo <theom+news@chiark.greenend.org.uk>
Newsgroups comp.sys.acorn.programmer
Subject Re: Name of a program
Date 2026-04-17 11:43 +0100
Organization University of Cambridge, England
Message-ID <F4l*XoiEA@news.chiark.greenend.org.uk> (permalink)
References <5cca837cdbbob@sick-of-spam.invalid> <5cca87776fNews04@avisoft.f9.co.uk> <5cca8d05ebbob@sick-of-spam.invalid> <01ece1ca5c.harriet@bazleyfamily.co.uk>

Show all headers | View raw


Harriet Bazley <harriet@bazleyfamily.co.uk> wrote:
> On 16 Apr 2026 as I do recall,
>           Bob Latham  wrote:
> 
> > In article <5cca87776fNews04@avisoft.f9.co.uk>,
> >    Martin <News04@avisoft.f9.co.uk> wrote:
> > > In article <5cca837cdbbob@sick-of-spam.invalid>,
> > >    Bob Latham <bob@sick-of-spam.invalid> wrote:
> > > > How can I get the name of program I'm running from within the
> > > > program?
> > 
> > > I would have thought that a program would know what it is called?!
> > > So not sure what you are wanting.
> > 
> > I want to hide the name of the source file in assemble code. I would
> > like to be able to look at my code and be able to find out which
> > source file it came from.
> 
> Do you mean 'embed' the name of the source file in assembly code?  I
> don't think it's inherently in the assembled machine code, which doesn't
> know whether it was assembled on the fly by running a parent BASIC file
> or loaded from disc and executed by calling the address of the area it
> was stored into, i.e. there is nothing to hide.
> 
> Or is this for the purposes of error trapping?
> 
> 
> Probably the best way to label your machine code is simply to manually
> embed a string near the top of it (like the string that is the name of a
> relocatable module) with EQUS, so that you can visually inspect it - or
> check for its presence at a known offset from the start of the code.

This sounds a bit like:

REM >Filename
file$ = FNgetmyfilename()
[
.myfunction_file
EQUS file$:EQUB 0:ALIGN
.myfunction_name
EQUS "myfunction":EQUB 0:ALIGN
.myfunction
<stuff>
ADR r0, myfunction_file
SWI "OS_Write0"
SWI &100+ASC":"  ; print a colon
ADR r0, myfunction_name
SWI "OS_Write0"
<stuff>
MOV pc,r14
]


Except I don't think the <get my filename> function exists for BASIC,
because BASIC doesn't have a concept of executing a file.  You might have
LOADed it into memory, but the name of the file given to LOAD isn't recorded
anywhere.  The command line from OS_GetEnv just tells you the *Command that
was run, which isn't quite the same.

What you could do is start at PAGE and then walk the tokenised code until
you spot a REM > statement, which is sort-of a convention for how to label
BASIC files with their filenames.  This wouldn't work if the file is part of
a LIBRARY, which is something you often do when assembling from multiple
source files.  It is also fairly nasty (eg would break if BASIC changed
its tokenisation, or if somebody renamed the file but failed to edit the
comment).

In C, it's easier because you have a macro __FILE__ which can be used to
embed the name of the source file into any string.  There are also 'debug
symbols' which can be enabled to annotate functions with their names to aid
in debugging.  BASIC doesn't have this (although if you were generating an
AIF binary in BASIC assembly you could hand-generate the debug symbols if
you wanted).

Theo

Back to comp.sys.acorn.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Name of a program Bob Latham <bob@sick-of-spam.invalid> - 2026-04-16 17:34 +0100
  Re: Name of a program Martin <News04@avisoft.f9.co.uk> - 2026-04-16 18:17 +0100
    Re: Name of a program Bob Latham <bob@sick-of-spam.invalid> - 2026-04-16 19:18 +0100
      Re: Name of a program Martin <News04@avisoft.f9.co.uk> - 2026-04-16 22:29 +0100
      Re: Name of a program Harriet Bazley <harriet@bazleyfamily.co.uk> - 2026-04-17 10:45 +0100
        Re: Name of a program Theo <theom+news@chiark.greenend.org.uk> - 2026-04-17 11:43 +0100
          Re: Name of a program Bob Latham <bob@sick-of-spam.invalid> - 2026-04-17 12:59 +0100
            Re: Name of a program Martin <News04@avisoft.f9.co.uk> - 2026-04-17 16:52 +0100
              Re: Name of a program Bob Latham <bob@sick-of-spam.invalid> - 2026-04-17 20:15 +0100
                Re: Name of a program Martin <News04@avisoft.f9.co.uk> - 2026-04-17 23:24 +0100
                Re: Name of a program Bob Latham <bob@sick-of-spam.invalid> - 2026-04-18 10:08 +0100
                Re: Name of a program Theo <theom+news@chiark.greenend.org.uk> - 2026-04-18 10:56 +0100
                Re: Name of a program Martin <News04@avisoft.f9.co.uk> - 2026-04-18 11:13 +0100
                Re: Name of a program Bob Latham <bob@sick-of-spam.invalid> - 2026-04-18 13:50 +0100
                Re: Name of a program Bob Latham <bob@sick-of-spam.invalid> - 2026-04-18 15:29 +0100
                Re: Name of a program Martin <News04@avisoft.f9.co.uk> - 2026-04-18 16:30 +0100
                Re: Name of a program Theo <theom+news@chiark.greenend.org.uk> - 2026-04-18 17:54 +0100
                Re: Name of a program Martin <News04@avisoft.f9.co.uk> - 2026-04-18 18:06 +0100
                Re: Name of a program Martin <News04@avisoft.f9.co.uk> - 2026-04-18 18:51 +0100
                Re: Name of a program Bob Latham <bob@sick-of-spam.invalid> - 2026-04-18 19:08 +0100
                Re: Name of a program Martin <News04@avisoft.f9.co.uk> - 2026-04-18 19:36 +0100
        Re: Name of a program Bob Latham <bob@sick-of-spam.invalid> - 2026-04-17 12:08 +0100
          Re: Name of a program Harriet Bazley <harriet@bazleyfamily.co.uk> - 2026-04-17 14:12 +0100
            Re: Name of a program Tank <webmaster@tankstage.co.uk> - 2026-04-17 15:09 +0100
              Re: Name of a program Harriet Bazley <harriet@bazleyfamily.co.uk> - 2026-04-17 19:35 +0100
              Re: Name of a program Bob Latham <bob@sick-of-spam.invalid> - 2026-04-17 20:17 +0100
                Re: Name of a program Martin <News04@avisoft.f9.co.uk> - 2026-04-17 23:30 +0100
      Re: Name of a program Steve Fryatt <news@stevefryatt.org.uk> - 2026-04-18 11:39 +0100
        Re: Name of a program Bob Latham <bob@sick-of-spam.invalid> - 2026-04-18 13:55 +0100

csiph-web