pouët.net

GNU assembler question (m68k)

category: general [glöplog]
 
I've been reading the GAS manual but haven't found a solution for this yet. I've got a program that outputs a bunch of data as an .s file. It contains several tables like this:

top_label:
.dw label_a
.dw label_b
.dw label_c

The file is then assembled with GAS and linked into a ROM. At runtime, a co-processor (which uses little-endian, and a 64k memory space) needs to use these tables. Using objcopy with --reverse-bytes on the object file in question before linking might've been a solution, but I also need to do some bitwise logic on the addresses. What I'd actually like to assemble is something like this:

top_label:
.db (label_a%256), ((label_a>>8)&0x7f)|0x80
.db (label_b%256), ((label_b>>8)&0x7f)|0x80
.db (label_c%256), ((label_c>>8)&0x7f)|0x80

That won't assemble because GAS complains about an "incorrect section" for those operations, probably because part of the expressions aren't absolute.
Is it at all possible to do label arithmetic such as this with GAS? If not - is there some other good 68k cross-assembler for wintel?

added on the 2010-01-21 17:39:14 by mic mic
What's your target platform? And what version of GAS are you using?
added on the 2010-01-21 17:49:10 by すすれ すすれ
My target platform is the Sega Megadrive, and I'm using binutils 2.18 (m68k-elf).
added on the 2010-01-21 17:52:42 by mic mic
uhh, isn´t there another choice maybe ?

i mean: this ain´t straight-forward :p !
Okay, I'll admit that I don't know much about dev tools on the Megadrive. Vasm (http://sun.hasenbraten.de/vasm/index.php?view=main) is a neat 68000 (cross-)assembler, unfortunately I don't see support explicitly for the Megadrive. Since the author is usually open to adding new target platforms, it wouldn't hurt to mail him asking for that.

Anyway, what I can suggest at the moment regarding your question(s) is:

- Since you're linking to a ROM file I suppose you're using absolute addresses. Most 68k assemblers (no idea about GAS) can assemble at absolute addresses using the ORG instruction. Maybe if you include something like this at the top of your code, GAS will get the point and stop complaining?
- Another idea would be to do this at runtime, something like:
Code: lea label_a(pc),a0 move.w a0,d0 ror.w #16,d0 bclr #7,d0 bset #7,d0 lea top_label(pc),a0 move.w d0,(a0)


(I'm not sure about the bset/bclr, that's what I think you're doing - I'm typing this fastish as I have to attend to something else soon :))

So this will generate the address regardless of the assembler. Hope this helps.
added on the 2010-01-21 18:52:28 by すすれ すすれ
Hi mic,

i think the GAS complains about the "%" operator, which is multiply used in GAS as far as i can remember. Have you tried using "&255" instead of "%256", which will result in the same byte value ?

Good luck with it ...
added on the 2010-01-21 19:08:45 by Paranoid Paranoid
@ggn: That's what I'm doing now, because now I'm copying the tables to the co-processor's (Z80) RAM. But I want to have the tables in ROM instead, to avoid wasting precious Z80 RAM. In case you're wondering why I don't just generate data for a Z80 assembler instead, it's because I don't want to assemble the data at some hardcoded address.
I don't use ORG at all. I use a .text section and a .bss section, and then I supply a linker script for LD which contains the base addresses for each section.

@Paranoid: Nope, still same error.


As a last resort I guess I could change the Z80 code that accesses these tables so that instead of:

ld hl,(table)

I'll do something like:

ld a,(table)
or $80
ld h,a
ld a,(table+1)
ld l,a

Though I would rather have avoided that.
added on the 2010-01-21 19:35:07 by mic mic
Never used GAS nor any megadrive, but I would expect something like this:

top_label:
.dw ( ((label_a&256)<<8) | (((label_a>>8)&0x7f)|0x80) )
.dw ( ((label_b&256)<<8) | (((label_b>>8)&0x7f)|0x80) )
.dw ( ((label_c&256)<<8) | (((label_c>>8)&0x7f)|0x80) )

hence the parenthesis are just to force evaluation, I've seen puking horses ;)

ofcourse one can try % (no <<8) but always use maximum parenthesis *G*
added on the 2010-01-21 22:03:18 by Danzig Danzig
Quote:
Code:ror.w #16,d0


FAIL! :D
added on the 2010-01-21 23:51:11 by StingRay StingRay
Quote:
Quote:
Code:ror.w #16,d0


FAIL! :D


Yeah, yeah, you whiny biatch, I know this won't assemble! Like I said, I wrote it in a hurry :)
added on the 2010-01-22 08:56:56 by すすれ すすれ
@Danzig
You mean "&255", surely..
added on the 2010-01-22 10:17:33 by xeron xeron
Quote:
Yeah, yeah, you whiny biatch, I know this won't assemble! Like I said, I wrote it in a hurry :)


That it won't assemble is not the only FAIL. :D
added on the 2010-01-22 15:57:55 by StingRay StingRay
Quote:
That it won't assemble is not the only FAIL. :D


Whine whine whine :P
added on the 2010-01-22 17:09:13 by すすれ すすれ
@xeron: SURE, thanks for nit-pick ;) copy/paste
added on the 2010-01-22 21:49:13 by Danzig Danzig

login