Welcome, Guest. Please login or register.

Author Topic: assembler related error using GCC  (Read 1071 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline cycloidTopic starter

  • Full Member
  • ***
  • Join Date: Jun 2002
  • Posts: 155
    • Show only replies by cycloid
assembler related error using GCC
« on: November 16, 2003, 11:00:56 PM »
Adoom is the only amiga doom port that i have the source for. i've managed to combine features of the linux makefile with the sas_c makefile and get one going. but now i'm stuck at what appears to be an assembler related error. and i know nothing about assembler (yet!)

it says, something along the lines of

parse error before __asm ...

e.g. void __asm functionheader( args, etc)


eventually i want to get prboom ported to the good old 68k :-)
 

Offline ncafferkey

  • Sr. Member
  • ****
  • Join Date: Feb 2003
  • Posts: 365
    • Show only replies by ncafferkey
Re: assembler related error using GCC
« Reply #1 on: November 21, 2003, 01:31:59 AM »
This isn't really related to assember, but to functions taking arguments in registers rather than on the stack. AFAIK you can safely remove that __asm between the return type and the function name when using GCC (but don't remove the __asm from any arguments). If you want the code to be compatible with as many compilers as possible, have a look at  dev/c/CLib-SDI.lha on Aminet for macros that allow this.
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16867
  • Country: gb
  • Thanked: 4 times
    • Show only replies by Karlos
Re: assembler related error using GCC
« Reply #2 on: November 21, 2003, 02:01:49 AM »

You should replace all instances of __asm with a macro, say _ASM or ASM that you can conditionally #define depending on the compiler.

Alternatively, as long as you know your target compilers regular calling mechanism, there is no need to define the function in any special way.

Assuming the compiler does the standard 'push args onto stack, then push return address onto stack' you can simply modify the asm code itself to properly save/restore whatever registers it clobbers, retrieve the args from the updated stack pointer and then do its stuff.

You can then leave the function declaration as a normal C one.

This approach does absolutely depend on knowing the compilers calling/return mechanism.

I cant say about gcc-680x0 without checking but, the normal convention for 680x0 is to push the args onto the stack (remember this is done with a predecrement mode, -(sp)) in the order they appear in the call. Bytes are padded out to words (to keep alignment) and lastly the return address is pushed.

For returns, integers are usually returned in d0 (or d0/d1 for long long), pointers in a0 and floats in fp0.

This approach is not portable amongst all compilers however (again it depends on calling mechanisms used).

I would say it is better to persuade the compiler to accept the asm as it is rather than changing the asm to suit the compiler...
int p; // A
 

Offline cycloidTopic starter

  • Full Member
  • ***
  • Join Date: Jun 2002
  • Posts: 155
    • Show only replies by cycloid
Re: assembler related error using GCC
« Reply #3 on: November 21, 2003, 10:07:28 PM »
i solved the problem in a way similar to what you describe. using a header file that defines macros for each compiler. i mention this in my other gcc/asm thread heh