Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site fortune.UUCP Path: utzoo!linus!philabs!cmcl2!floyd!clyde!ihnp4!fortune!shah From: shah@fortune.UUCP Newsgroups: net.micro.68k Subject: Re: Does anyone have nargs() for the 680 - (nf) Message-ID: <2104@fortune.UUCP> Date: Sun, 25-Dec-83 15:03:17 EST Article-I.D.: fortune.2104 Posted: Sun Dec 25 15:03:17 1983 Date-Received: Tue, 27-Dec-83 00:22:48 EST Sender: notes@fortune.UUCP Organization: Fortune Systems, Redwood City, CA Lines: 48 #R:utcsrgv:-298800:fortune:6600004:000:1593 fortune!shah Dec 25 10:46:00 1983 Here is one version of nargs. You may have to tweak it a little to keep your assembler/compiler happy. The idea is to check for the instruction after "jsr my_caller". If it is a stack pointer adjusting instruction the caller was called with one or more arguments. -- Bakul Shah {sri-unix,amd70,hpda,harpo,ihnp4,allegra}!fortune!shah =-=-=-=-=-=-=-=-= ; nargs() ; -- returns the number of arguments supplied to the caller ; assumes that our caller has done a link %a6,xxx #define ADDQ_8_A7 0x508f /* addql #8,%a7 */ #define ADDQ_4_A7 0x588f /* addql #4,%a7 */ #define ADDL_XX_A7 0xdffc /* addl #xxxx,%a7 */ .text .globl nargs nargs: movl %a6@(4),%a0 ; %a0 = caller's caller's pc movw %a0@,%d0 ; %d0 = next inst (1st word) cmpw #ADDL_XX_A7,%d0 ; is this addl #xxxx,%a7 ? bne 1$ ; no, skip to next test movl %a0@(2),%d0 ; #xxxx from addl #xxxx,%a7 to %d0 asrl #2,%d0 ; div by 4 to get NUMBER of args rts 1$: cmpw #ADDQ_8_A7,%d0 ; is this addql #8,%a7 ? bne 2$ ; no, skip to next test moveq #2,%d0 ; 2 args rts 2$: cmpw #ADDQ_4_A7,%d0 ; is this addql #4,%a7 ? bne 3$ ; no, this routine has no args moveq #1,%d0 ; 1 arg rts 3$: clrl %d0 ; no args (or the compiler fooled us!) rts =-=-=-=-=-=-=-=-=