PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

GCC Assembler and MS Assembler

Is there a way to convert .o files compiled using GCC's GAS assembler into the .obj format used by Microsoft compilers?

I'm writing a bit of assembler, but don't want to write it twice, once for use with armasm and once for gas...
bluescrn · 22 Sep 2003, 09:02 UTC — GCC Assembler and MS Assembler
Dave H wrote:
Is there a way to convert .o files compiled using GCC's GAS assembler into the .obj format used by Microsoft compilers?

I'm writing a bit of assembler, but don't want to write it twice, once for use with armasm and once for gas...


I'm planning to use GoldRoad (or any other assembler) to assemble my code to raw binary, and load the code at runtime, with platform-specific 'LoadARMCode()' and 'CallARMFunc()' type routines

(That's assuming PocketPC and Symbian ARM devices allow you to actually execute code from an apps data area... I think they will but haven't tested it yet...)

I'm also planning to run the ARM code natively on PC debug builds using an ARM CPU emulator hacked to directly access the x86 memory space... With enough time/effort, this could be extended to allow full ARM debugging features within a PC build...

The main problem is finding an ARM CPU emulator that's not GPL-encumbered (like the one in VisualBoyAvance, which I've experimented with). I'd have no problems giving away source to an 'ARM on PC' framework/test rig, but wouldn't want to let the GPL 'infect' my whole engine/game
Dave H · 22 Sep 2003, 21:38 UTC — GCC Assembler and MS Assembler
bluescrn":5wcywwh7]


Have just been trying something similar - here is the process:
Use 'as' (gnu assembler) to compile the .s file to an .o file.
Use 'objcopy' to output as binary (.bin file)
Write out the .bin file as an array in C (unsigned int data[]={0xe1000xxx etc}; )
Link the C with the program, and then cast the array as a function and execute it.

FYI it all works fine, no data area problems as of yet. However watch out for Labels: all labels information is of course stripped, but this means that long jumps are WRONG in the assembler, because of course they are fixed relative to the start of the .bin file not the resulting .exe file.

This is a bit of pain, what I have to do is at run-time figure out where I am, set it to a register and then add on this register everytime I do a 'bl' (basically do a ldr r0,=Label; add pc,r10,r0).

So I'm not sure how good this route is... if ONLY there was some kind of objcopy which could spit out .obj files, or a kind of NASM for ARM, I would be so much happiler.

As for writing an ARM emulator, it's probably a bit easier than a lot of other emulators, because of the RISC nature of ARM, you might be able to do it from scratch
I've not needed long jumps so far, as I'm only planning to write fairly small ARM functions (poly rasterization), so everything is relocatable so far

As for the ARM emulation, I did a quick test and got my ARM screen clear function running on an x86 build with a bodged version of the ARM core from VisualboyAdvance

I'm wondering if there's a 'GPL workaround' possible by keeping the ARM emulation (and eventual debugging) as a separate program - a GPL'd tool, which could be used to help develop closed-source games if desired.

But the ARM emulator needs access to pretty much all of the target app's data memory... don't really fancy using windows messaging to request individual reads/writes (!!!). Although it would be possible....

I need to read up on Win32 stuff, and see if/how I can get 2 apps to communicate/share memory efficiently...
StephC · 22 Sep 2003, 22:26 UTC — GCC Assembler and MS Assembler
Dave H wrote:
I'm writing a bit of assembler, but don't want to write it twice, once for use with armasm and once for gas...


It's very easy to convert the .asm to the .S format, almost nothing differ...

Only labels, comments (there is a way to write cross compatible comments) and headers.

Personnaly I always write C code for the PC build and switch (#define ASM) the asm code for PocketPC and Zaurus build.
Dave H · 23 Sep 2003, 13:18 UTC — GCC Assembler and MS Assembler
StephC":j4l8jgth]


Can you tell me how to write cross compatible comments?
Surely the ; character can be used for a line comment in both? (Unless my memory is as poor as I suspect :)).
refractor wrote:
Surely the ; character can be used for a line comment in both? (Unless my memory is as poor as I suspect :)).


No, however inspired by the above post, I did try using ;@ for a comment and it seems to work in both armasm and gas...

Perhaps that's what he meant?

This may be enough to get something compiling fairly easily in both armasm and gas actually! Fingers crossed