Welcome, Guest. Please login or register.

Author Topic: compiling assembly.s files in gcc ... was: gcc wont compile with // comments?  (Read 13528 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16878
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: compiling assembly.s files in gcc was: gcc wont compile with // comments?
« Reply #29 from previous page: December 09, 2009, 01:36:44 PM »
Quote from: NovaCoder;533113
To continue this old thread....

(snip)

Anyone got any ideas?


I got around all my C++ / asm combination problems by using inline C++ functions that call asm() construct directly.

For example
Code: [Select]

  inline uint32 swap32(uint32 val)
  {
    if (__builtin_constant_p(val)) {
      val = val<<16 | val>>16;
      val = ((val&0x00FF00FF)<<8) | ((val&0xFF00FF00)>>8);
    } else {
      asm(
        &quot;rol.w #8, %0\n\t&quot;
        &quot;swap %0\n\t&quot;
        &quot;rol.w #8, %0&quot;
        : &quot;=d&quot;(val)
        : &quot;0&quot;(val)
        : &quot;cc&quot;
      );
    }
    return val;
  }


You can (and I have) used the asm() statement inside an inline C++ function to jsr to an externally referenced function written in assembler. Just make sure the variables passed to your inline function are loaded into the correct registers inside the asm() just before you jsr and add those registers to the clobber list so the compiler knows your call is going to trash them.
« Last Edit: December 09, 2009, 01:40:07 PM by Karlos »
int p; // A
 

Offline NovaCoder

Re: compiling assembly.s files in gcc was: gcc wont compile with // comments?
« Reply #30 on: January 13, 2010, 05:53:02 AM »
Quick update (for reference):

So now I'm using PhxAss to compile the assembly files to object files and adding them to my StormC project. I then have to use a stub declaration as follows to call the underlying assembler function:

Code: [Select]

void c2p1x1_cpu3blit1_queue_stub(UBYTE *c2pscreen, UBYTE *bitplanes) {

UBYTE * _c2pscreen = (c2pscreen);
UBYTE * _bitplanes = (bitplanes);

register UBYTE * __c2pscreen __asm(&quot;a0&quot;) = _c2pscreen;
register UBYTE * __bitplanes __asm(&quot;a1&quot;) = _bitplanes;
__asm volatile ( &quot;jsr _c2p1x1_cpu3blit1_queue&quot; : : &quot;r&quot; (__c2pscreen), &quot;r&quot; (__bitplanes) : &quot;d2&quot;, &quot;d3&quot;, &quot;d4&quot;, &quot;d5&quot;, &quot;d6&quot;, &quot;d7&quot;, &quot;a2&quot;, &quot;a3&quot;, &quot;a4&quot;, &quot;cc&quot;, &quot;memory&quot;);
}
Life begins at 100 MIPS!


Nice Ports on AmiNet!