🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #52598

asm() operands outside of functions

#52598
From: Andrew McRae
Date: Fri, 26 Jun 1992 02:12
59 lines
2121 bytes
Environment: gcc 2.2.2 cross compiling to a 68000 on
a Sparcstation (SunOS 4.1.1).

Can I use the extended asm() operand constraints outside of
a function in GCC? I get an error for the following
line of code:

	asm(" movew  #%0,sp@-" : : "n" (0));

x.c:1: parse error before `:'

When I surround the statement with a function, it works e.g

dummy()
{
	asm(" movew  #%0,sp@-" : : "n" (0));
}

Why do I want to do this? I want to embed some #define'd constants
into an assembler macro e.g

#define	BUSERR		0
#define	ADDRERR		1
#define	ILLG_INSTR	2
#define	UNKNOWN_INTR	3
#define	CHK_ERR		4
#define	ZERO_DIV	5
#define	TRAPV		6
#define	PRIV_ERR	7
#define	TRACE		8
#define	FORMAT		9
#define	BREAKPOINT	10
#define	SPURINT		11
#define	NMI		12

#define	EXCEPT_HAND(entry, code) \
	asm(" .globl _" #entry); \
	asm("_" #entry ":"); \
	asm(" movew  %0,sp@-" : : "n" (code)); \
	asm(" bra hand_except");

	EXCEPT_HAND(buserror, BUSERR);
	EXCEPT_HAND(addrerror, ADDRERR);

etc...

One workaround is to place all the asm()'s in a dummy function,
but this seems an unnecessary and contrived action.

I see in cp-parse.y that it does not support the asm operands when
asm is used outside of a function. Is there any reason why not?
It would be useful to use the operands to pick up enums etc.

Thanks for any answers.

Andrew McRae			inet:	andrew@megadata.mega.oz.au
Megadata Pty Ltd,		uucp:	..!uunet!megadata.mega.oz.au!andrew
North Ryde  2113		Phone:	+61 2 805 0899
NSW    AUSTRALIA		Fax:	+61 2 887 4847
Technical Details
Message-ID: <1992Jun26.021227.8728@megadata.mega.oz.au>
Path: arc1-ca.pugleaf.net!sparky!uunet!munnari.oz.au!metro!dmssyd.syd.dms.CSIRO.AU!megadata!andrew

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,7f029fe49ce7c374,start
X-Google-Attributes: gid11318c,public
X-Google-ArrivalTime: 1992-06-25 14:30:02 PST
Newsgroups: gnu.gcc.help
Path: arc1-ca.pugleaf.net!sparky!uunet!munnari.oz.au!metro!dmssyd.syd.dms.CSIRO.AU!megadata!andrew
From: andrew@megadata.mega.oz.au (Andrew McRae)
Subject: asm() operands outside of functions
Message-ID: <1992Jun26.021227.8728@megadata.mega.oz.au>
Sender: news@megadata.mega.oz.au
Organization: Megadata P/L, North Ryde, Sydney, Aust.
Date: Fri, 26 Jun 1992 02:12:27 GMT
Lines: 59