[comp.unix.microport] How can one do inline assembler under Sys5?

chuck@coplex.UUCP (Chuck Sites) (03/30/88)

   Could anyone out there tell me what the syntax is for the
C compiler (cc) to do inline assembly lanuage under Unix
System 5.  Does this feature still exist or has it been removed
by the purists?  I can't find it anywhere in the documentation
and yet the C compiler containd some error messages regarding the 
asm construct.

   Speaking of assembler under unix, does anyone one have 
documentation on the neumonics for the 286 & 386 asm codes?
I've been able to figuare out most of the neumonics, but some
of the assembler directives really puzzle me.  
 
   Also in the same light of reporting undocumented things, here's
one.   The 'dis' command has an undocumented switch which may be
useful to some.  It's the -F parameter.   It allows one to select
a specific global function for examination when doing a 'dis'. 
  
dis -F function file




  +-----------------------------------------------+    +---------+
 /:::::::::Copper Electronics Inc::::::::::::::::/|   /:::::::::/|
+-----------------------------------------------+/|  +---------+/|
| CHUCK SITES   chuck@coplex.UUCP               |/|  |   ___   |/|                      
| UUCP: {mit-eddie}!bloom-beacon!coplex!chuck   |/+  |  / / \  |/+
| FLAME ADDRESS: /dev/null                      |/   |  \/__/  |/
+-----------------------------------------------+    +---------+

chuck@coplex.UUCP (Chuck Sites) (04/05/88)

In article <396@coplex.UUCP>, chuck@coplex.UUCP (Chuck Sites) writes:
>    Could anyone out there tell me what the syntax is for the
> C compiler (cc) to do inline assembly lanuage under Unix
> System 5.

I wanted to followup on this subject again since it might help some other developers
out there.  I had lots of nice mail from others out there most of which said, "basically
Chuck, it can't be done."  Thanks guys :-)  I was quite pleased to find out this is not
the case and 'YES', there is a way to perform inline assembly language with the standard
unix (cc) compiler with stock System 5. Look in /usr/include/prof.h for a good example.
(Thanks for the tip Jeff, but what is /usr/include/sys/inline.h?)  Anyway it works like:

some_function(x)
int x;
{
	asm("	mov %dx,%ax");	 /* Inline assembler at work */ 
	asm("   mov %cx,%ax");   /* One minor annoying thing ... */   
	asm("   mov %bx,%ax");   /* Only one line of assembler per */
	asm("   nop");           /* asm() call seems to be allowed */
	asm("Yes I know this line will cause an error ");
	asm("But after all, this is a demo function ");   
}

compile with 'cc function.c -S' if you want to examine the assembly lang output.
It is a quite awkward construct to use in practice but at least it's something.
I have found this on two different Unix system 5's so I suspect it's a pretty standard
method of doing inline assembler.  

  I have found that most of the assembler directives are fairly standard regardless of
the platform they're on like .global, .text, .data.  But apparently thier are others
specific to the segmented achitecture of the 286.  Does any one have doc's on these?
Care to post-em?

  +-----------------------------------------------+    +---------+
 /:::::::::Copper Electronics Inc::::::::::::::::/|   /:::::::::/|
+-----------------------------------------------+/|  +---------+/|
| CHUCK SITES   chuck@coplex.UUCP               |/|  |   ___   |/|
| UUCP: {mit-eddie}!bloom-beacon!coplex!chuck   |/+  |  / / \  |/+
| FLAME ADDRESS: /dev/null                      |/   |  \/__/  |/
+-----------------------------------------------+    +---------+

bowles@lll-crg.llnl.gov (Jeff Bowles) (04/06/88)

If you have certain releases of the System V compiler, you have
extended assembler statements. The following is documented in the
paging "C Compilation System" release notes for the 3B2, I think,
and hasn't made it into other docs yet. It's the same mechanism
you'll find in /usr/include/sys/inline.h on many V.3 releases.

It's useful to inspect the output ("cc -S") - you'll notice that you
can generate certain sequences if the argument is in a register
(or constant or memory) and the like.
	Jeff Bowles

------------------------------------------------------------------------

asm	int retzero()
{
	movl	$0, %eax
}

asm	int clr(z)
{
%mem	z;
	movl	$0, z
}

asm	int com(z)
{
%reg	z;
	imull	$-1,z,z
%mem	z;
	neg	z
}

main()
{
	int z = -1;
	register zreg = -1;

	z = retzero();
	printf("Z = %d\n", z);
	z = -1;
	printf("Z = %d\n", z);
	clr(z);
	printf("Z = %d\n", z);
	z = -1;
	printf("Z = %d\n", z);
	printf("Reg = %d\n", zreg);
	com(z);
	com(zreg);
	printf("Z = %d\n", z);
	printf("Reg = %d\n", zreg);
}