Get address of label from other source files

All 680x0 related coding posts in this section please.

Moderators: simonsunnyboy, Mug UK, Zorro 2, Moderator Team

Post Reply
chicane
Atari maniac
Atari maniac
Posts: 90
Joined: Mon Jul 02, 2012 11:25 am
Location: Leeds, UK

Get address of label from other source files

Post by chicane »

I'm working on an ST game modification project (see http://www.atari-forum.com/viewtopic.php?f=3&t=38060) where I'm updating functionality by replacing areas of code in memory with code I've written myself. The code I've written myself is located in multiple assembly source files. The contents of each source file, once compiled to binary code, is intended to be overlaid on the existing code at a given memory address. I'm using VASM to assemble the source files.

I'm getting to the point where it would be convenient to store values in memory that I can share between different source files. This is easy enough within the context of a single file:

Code: Select all

[file1.s]

ORG $12345

graphicsdata:
    dc.w 1234
...
...
...
...
    lea graphicsdata,a1
But is there any way, following the assembly of file1.s, that I could have another file, named file2.s, that could somehow identify the absolute address to which the "graphicsdata" label was assembled in file1.s?

The alternative is to manually identify the address of the label in file1.s and keep all references to that address updated in other files if and when the address changes. This seems clunky and error-prone.

Thanks for any thoughts on this - I'm stumped!
ThorstenOtto
Atari God
Atari God
Posts: 1190
Joined: Sun Aug 03, 2014 5:54 pm

Re: Get address of label from other source files

Post by ThorstenOtto »

Solution 1: define the value for the label in a separate file, and include that in both sourcefiles
Solution 2: export the label by using something like ".globl graphicsdata" in file1, and also ".globl graphicsdata" in file2 to import it there (but that only works if file1 and file2 are linked together)
User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 2711
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: Get address of label from other source files

Post by charles »

store a loader in the tos at fixed address or ram disk with data ?
The radioactive half-life : )
Atari is a lifestyle,not a hobby.
HOLD ON ! ! ! Im printing unreadable characters ...!
chicane
Atari maniac
Atari maniac
Posts: 90
Joined: Mon Jul 02, 2012 11:25 am
Location: Leeds, UK

Re: Get address of label from other source files

Post by chicane »

Thanks both for your suggestions.
ThorstenOtto wrote:Solution 1: define the value for the label in a separate file, and include that in both sourcefiles
Solution 2: export the label by using something like ".globl graphicsdata" in file1, and also ".globl graphicsdata" in file2 to import it there (but that only works if file1 and file2 are linked together)
Solution 2 would be ideal, but unfortunately I won't be linking the files together.

With respect to Solution 1, the issue I have is that I need access to the absolute memory address at which the label resides, and this can only be established once file1.s has been assembled. So in order for file2.s to get the value it needs, file1.s first needs to be assembled, during which the absolute address of the label is provided as a side-effect. This information can then be used within file2.s.

I have come across an option in VASM (-L) that provides a line-by-line log of the assembly process:

Code: Select all

F00:0001           ORG $7a312
F00:0002
F00:0003           tst.w     d2 ; set flags for d2
               S01:0007A312:  4A 42
F00:0004           bpl.s     label_7a32c ; branch if d2>0
               S01:0007A314:  6A 16
F00:0005           tst.w     d6
               S01:0007A316:  4A 46
F00:0006           bmi       label_7a63a
               S01:0007A318:  6B 00 00 94
This log looks (with some parsing) as if it'll give me the information I need - I can parse the file to output an include file that will contain a list of labels along with the addresses to which they've been assembled. The file doesn't really look like it's intended to be machine-readable but I suspect that it's the best option open to me as things stand :)
charles wrote:store a loader in the tos at fixed address or ram disk with data ?
Thanks for your suggestions. I'm looking to avoid fixed addresses if possible (for a couple of reasons) and a ram disk might be a bit overkill for this need :)
User avatar
Arne
Atari Super Hero
Atari Super Hero
Posts: 646
Joined: Thu Nov 01, 2007 10:01 am

Re: Get address of label from other source files

Post by Arne »

I don't know if I got you right. You want some kind of global Get/Set functions for getting/setting variables?
If this is the case then you may try to set up your own Trap-Handler (i.e. not BIOS/XBIOS/...) with a function number put on the stack to get/set a certain variable. As shared memory for exchanging the data use a malloc() block which start address is set via a function number for that trap.
All your other code snippets then just "call" the trap.
Image
ThorstenOtto
Atari God
Atari God
Posts: 1190
Joined: Sun Aug 03, 2014 5:54 pm

Re: Get address of label from other source files

Post by ThorstenOtto »

chicane wrote: Solution 2 would be ideal, but unfortunately I won't be linking the files together.
For solution 1 (using an include file) you don't need tolink them together. But looks that you not only need the value of some absolute address that you defined, but also some others that depend on file1.s
The file doesn't really look like it's intended to be machine-readable but I suspect that it's the best option open to me as things stand :)
You can also use m68k-atari-mint-nm (from gcc binutils) to print the addresses of all symbols of the resulting object file. Whatever format vasm generates, nm should be able to handle it. Or alternatively, try cnm from the mintbin repo. Both are available eg. at http://tho-otto.de/crossmint.php
chicane
Atari maniac
Atari maniac
Posts: 90
Joined: Mon Jul 02, 2012 11:25 am
Location: Leeds, UK

Re: Get address of label from other source files

Post by chicane »

Arne wrote:If this is the case then you may try to set up your own Trap-Handler (i.e. not BIOS/XBIOS/...) with a function number put on the stack to get/set a certain variable.
Thanks - this is an elegant solution and did cross my mind. This is a game environment so I'm a bit wary of the performance implications though.
ThorstenOtto wrote:You can also use m68k-atari-mint-nm (from gcc binutils) to print the addresses of all symbols of the resulting object file.
Thanks - this was really helpful. I've now managed to use nm in conjunction with a bit of text processing to extract the addresses of the labels and transform them into a list of equ clauses for use in an include file. Works a treat!
Post Reply

Return to “680x0”