Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!cmcl2!rutgers!mcnc!ece-csc!ncrcae!ncr-sd!ncrlnk!ncrpcd!wright!jholbach From: jholbach@wright.EDU (Jim Holbach) Newsgroups: comp.lang.c Subject: Re: asm statements & the stack Message-ID: <184@wright.EDU> Date: Sat, 10-Oct-87 12:59:11 EDT Article-I.D.: wright.184 Posted: Sat Oct 10 12:59:11 1987 Date-Received: Mon, 12-Oct-87 18:39:45 EDT References: <110@teletron.UUCP> Organization: Wright State University, Dayton OH, 45435 Lines: 35 in article <110@teletron.UUCP>, andrew@teletron.UUCP (Andrew Scott) says: > > The compiler I use (stock AT&T /bin/cc) does a wierd thing upon the call to foo. > It allocates one more longword than necessary when creating foo's stack frame. The logic I've read for this is that it reduces the amount of pushing and popping required for function calls (from within functions) because at least one longword is always sitting on the stack. Only when more than one parameter is used, is it necessary to change the stack pointer. (This was from the manual for C with CPM-68K but it seems that the same logic is involved here. ) > This really messes up the intended action of disable, because the saved > status register is overwritten. > > To conclude a long story, should I really be angry at whoever wrote the compiler > for doing such a strange thing, or should I avoid asm statements altogether > because I can't count on anything? The alternative is rather barfy: > require the use of disable & restore are all quite time critical. Why not just adapt your definitions of enable/disable to the observed behavior of your compiler? Since you know and accept that the definitions are machine/compiler specific, how about something like the following: #define disable asm("mov.w %sr,(%sp)"); \ asm("mov.w &0x2700,%sr"); \ asm("sub.w &4,%sp") #define restore asm("add.w &4,%sp"); \ asm("mov.w (%sp)+,%sr") Jim Holbach Wright State University Dayton, Ohio