A.D.A. Amiga Demoscene Archive

        Welcome guest!

  

  

  

log in with SceneID

  

Demos Amiga Demoscene Archive Forum / Coding / Mixing Languages
 Page:  1  2  3  »» 
Author Message
bonkers
Member
#1 - Posted: 29 Jan 2005 21:45
Reply Quote
Just looking for some stats here, and maybe some help later =)

How many of you are mixing ASM and C?

I've always done all the demo code in 100% asm and only separate programs in C like LW exporter and similar things, but I've never mixed languages in one executable.
kas1e
Member
#2 - Posted: 30 Jan 2005 10:28
Reply Quote
I am writing all code on C (sasc basically), and mixing it with asm objects by
phxass asm compiler. On asm i replacing memcpy/etc fucntions. phxass syntax is the same as devpac basically.
kufa
Member
#3 - Posted: 31 Jan 2005 09:35
Reply Quote
it works pretty well (cf tbl demos)
rload
Member
#4 - Posted: 31 Jan 2005 13:05 - Edited
Reply Quote
I tried VBCC with PhxAss. Works pretty well.. Just xdef symbols that should be accessible from C and declare them extern in the C file.. And remember the underscore in front of variables if you want them in C..
<asm>
xdef _number
xdef _func

_number dc.l 0

_func move.l #10, d0
rts
</asm>

<c>
extern int number
extern int func()

int main() {
int res;
number = 5; /* Do something to number */
res = func(); /* Res becomes 10 (D0)

}
</c>

Return values for c functions return in d0... I dont know how parameter passing to C is done yet.. anyone?
krabob
Member
#5 - Posted: 31 Jan 2005 13:57
Reply Quote
yeah... what loaderror said, plus:

(I also use phxass for asm and currently stormc/gcc.
mixing c and asm is very easy with 680x0 because the way the registers are used are the same on any systems. PowerPC is a bit more difficult.)

note if you want to use some C global stuffs in your asm, the asm equivalent for "extern" is "xref", that way you can share anything through any .o You know C compilations first create an assembler file (option -s with a compiler) , and then assemble it to ".o" to link.

For the parameters: the way parameters are passed through a function is defined by the application binary interface (ABI). for 680x0, it is something like:

d0/d1/a0/a1: are VOLATILE: they can be trashed when passing to a func.
d2-d7/a2-a6: had to keep the same when coming back from a func.

it means in a 'c resusable asm func' you have to do:
xdef _func
_func
movem.l d2-d7/a2-a6,-(sp)
...
movem.l (sp)+,d2-d7/a2-a6,
rts
of course, if none of d2,... are used in all your functions you don't have to stack it. If you do asm only source, you don't have to apply ABI rules, but
a C-usable asm entry fonction have to. (but sub-asm function don't have to !)

then now, how to pass argument in the function ? in most case, the ABI say:

int myfunc(struct mypoint *pointer1, int val1, void *point2,int val2)

the 2 first values that are not pointers SHOULD be passed to d0 and d1,
in the same order. the pointer should be mapped to a0,a1 in the same order. meaning this:

pointer1 <- a0
point2 <-a1
val1 <- d0
val2 <- d1

also, the other argument should be passed in the stack, before your movem. so you know what ? making assumption to what should be mapped to what is shitty. hopefully , each C compiler knows a syntax to force argument to be passed in a given register. use THAT.












a value returned, may it be a pointer or an integer is returned with d0.
For the incoming parameters
krabob
Member
#6 - Posted: 31 Jan 2005 16:38
Reply Quote
arghh sorry, I couldn't finish. here is the end of the previous post:

Each compiler know a syntax to force the mapping of a given C argument to a assembler register.

With StormC4/gcc I define my external asm function in a .h with something like:

extern __reg("d0") struct TextureContext * MakeColorTable(
__reg("a0") struct TextureContext *Texture,
__reg("a1") ULONG *PaletteRGB32,
__reg("d0") int type_palxpal,
__reg("d2") int R,
__reg("d3") int G,
__reg("d4") int B
);

... this way, you can simply re-use the register at the entry of your asm functions... After a quick search, this syntax is also valid for vbcc. Look your compiler docs to know what you need to do.
kufa
Member
#7 - Posted: 2 Feb 2005 22:23
Reply Quote
And if you want to mix C++ with asm, use extern "C" instead of extern ;)
rload
Member
#8 - Posted: 14 Feb 2005 03:14
Reply Quote
mixing c++ and asm is also possible by adding random gibberish to the end of every function

class foo {
public:
foo();
void bar( int a );
private:

feelings:
bool sad();
}

extern foo::bar()

this may now be reached from asm by

jsr ___foo145::bar935803vkjburr

or

jsr ___foo1353::barbar5367568vvv

it doesnt matter.. they just tried to fool us with extra difficult names..
krabob
Member
#9 - Posted: 1 Mar 2005 11:46
Reply Quote
hehe, very interesting loaderror. But ... how to you get the "this" pointer
in your foo() asm method ? and how do you pass it ? does it use a special register ?
StingRay
Member
#10 - Posted: 7 Dec 2005 13:51
Reply Quote
I do everything in 1oo% asm. =)
toffeeman
Member
#11 - Posted: 8 Dec 2005 01:20
Reply Quote
Is Krabob the guy who wrote Jesus is a demomaker ? That demo was excellent and had some great code !
winden
Member
#12 - Posted: 8 Dec 2005 15:07
Reply Quote
tof, yes krabob is the coder for jesus was a demomaker, scrap of beings, new world child and some more stuffs
z5_
Member
#13 - Posted: 13 Jan 2006 12:44
Reply Quote
From my point of view (a newbie that has limited experience with c, c++, pascal and visual basic), it seems completely mad to still want to learn assembler in 2006 :)

I mean, i was reading up on some pc tutorials on effects like plasma, fire, tunnels,... and they only took 10 or 20 lines of code at maximum. You can use things like sine, random, modulo,... while in assembler, you have to invent/create/whatever them yourself. A lot of time waisted on stuff which seems very boring and time-consuming and difficult, hence a very steep learning curve in the beginning.

In the end, i would have loved to use c myself, mixed with a bit of assembler. But then again, i don't have a graphics card so i'm stuck with 640*256 resolution workbench so setting up a decent c developer environment is out of the question.
kufa
Member
#14 - Posted: 1 Feb 2006 01:41
Reply Quote
mixing c++ and asm is also possible by adding random gibberish to the end of every function

Well, yes and no. You have something called name mangling going on. Each compiler will use different names for methods and functions. But, you can still use readable names but only implementing in assembly non object members functions, and adding extern C:

#ifdef __cplusplus
extern "C" {
#endif
int myAsmFunction( int a, int b ); // use registers if you want
#ifdef __cplusplus
}
#endif

...
xdef _MyAsmFunction
_MyAsmFunctin
rts

So implementing in asm a class method is just a matter of calling another routine, well if you dont want having to fight with weird names. (and if you dont want to check if the object pointer is passed thru a0)

Got my article for JP almost ready, changed from StormC to gcc (beeeetter template support)..
winden
Member
#15 - Posted: 1 Feb 2006 11:34
Reply Quote
vbcc has not been working too well for me, at least when running under UAE/OSX it scribbles memory all over and hangs the machine... not tested it yet on real hardware, does it work OK?
kufa
Member
#16 - Posted: 8 Feb 2006 05:16
Reply Quote
i dont use vbcc, but afaik tbl is using it now. I use gcc (well a version i found using a link on gurumeditation.net, http://www.kefren.be/modules.php?name=Downloads&d_ op=viewdownload&cid=1 to be precise) and so far so good.
krabob
Member
#17 - Posted: 8 Feb 2006 13:37
Reply Quote
the shit is, as a coder, I 'm completely "object oriented" now, and vbcc doesn't manage C++, AFAIK.
krabob
Member
#18 - Posted: 8 Feb 2006 13:38
Reply Quote
(but amigaos 's ".library" can't manage C++ either, ... )
rload
Member
#19 - Posted: 8 Feb 2006 20:47
Reply Quote
how can one link gcc stuff to phxass object files? I heard that it doesn't work straight out of the box. Anyone know how does it work? the gcc frontend should be pretty smart by now. don't know if the 68K backend is very good, but it may be more mature than vbcc's. VBCC is fine most of the time, but sometimes it seems a bit strange.
kufa
Member
#20 - Posted: 9 Feb 2006 15:53
Reply Quote
You have to use hunk2aout. I'm not sure, but i think the gcc compiler inside stormc dont need that,will check later today. Guyz, i should give you my "mixing assembly and c/c++" article for jp15 for a review :)
bonkers
Member
#21 - Posted: 10 Feb 2006 00:36
Reply Quote
@kufa
Looking forward to see that article.
rload
Member
#22 - Posted: 10 Feb 2006 16:50
Reply Quote
@kufa
me too. It is time we started C coding. Maybe the number of releases can grow from one a year to two times a year., :)
Anonymous
Member
#23 - Posted: 13 Feb 2006 12:59
Reply Quote
Demos are not supposed to be coded in C, at least not on 68k. :)
StingRay
Member
#24 - Posted: 13 Feb 2006 13:01
Reply Quote
Last post was written by me, the damn forum logged me out and I didn't notice. :)
dalton
Member
#25 - Posted: 14 Feb 2006 00:43
Reply Quote
An old swedish anecdote comes to mind...

Det var två blinda programmare och en kunde C.
krabob
Member
#26 - Posted: 14 Feb 2006 12:42
Reply Quote
... We should simply begin wrestling death match !
To my left, he is one of the more sharp coder out there !

** STRINGRAY ** (clap clap clap clap)

And to my Right, it is the worldwide known gnu C compiler !
** GCC ** (clap clap clap also)

... now we take some 10-20 lines C functions and begin the 68020 ASM battle !
krabob
Member
#27 - Posted: 14 Feb 2006 12:47
Reply Quote
... just to notice: I 've just done that bit myself, with some short-code options, and GCC won most of the times. Actually, for some loop coding you can beat it, but, for example, if you do something like intv1 |= ((intv2&63) <<6) , it will manage to use bfins.
StingRay
Member
#28 - Posted: 15 Feb 2006 16:04
Reply Quote
Krabob: I didn't say that C/C++ is bad, just to make that clear. Still I think, if you want to have the fastest possible code (and demos are supposed to have the fastest code ;D), hardcore asm hacking is the only choice!
kufa
Member
#29 - Posted: 16 Feb 2006 01:43
Reply Quote
Sting: i think we all agree with that, asm is faster in any case. BUT in term of development time, doing all the boring stuffs in c/c++, all the scripting engine etc, can be done in c/c++ without a big impact on performance, and it's much faster to code and tweak usually. And testing new effects is pretty easy in c, then we can just optimize them in asm! wanna get my [s] c/c++ start of demosystem in c++ and help me on that? :P
krabob
Member
#30 - Posted: 16 Feb 2006 11:54
Reply Quote
We all agree it's fantastic !!! ah aha ha !!! what a joy of a furum !
 Page:  1  2  3  »» 

  Please log in to comment

  

  

  

 

A.D.A. Amiga Demoscene Archive, Version 3.0