From:	SMTP%"RELAY-INFO-VAX@CRVAX.SRI.COM" 12-AUG-1993 21:28:03.99
To:	EVERHART
CC:	
Subj:	Re: Q: How to access 8(SP) in Alpha/AXP ?

Date:    Thu, 12 Aug 93 12:41:27 PDT
From:     mahan@TGV.COM (Patrick L. Mahan)
Message-Id: <930812124127.10008bb@TGV.COM>
Subject: Re: Q: How to access 8(SP) in Alpha/AXP ?
To:       ichihara@rikvax.riken.go.jp, info-vax@sri.com
X-ST-Vmsmail-To: ST%"ichihara@rikvax.riken.go.jp"

In article <1993Aug12.015110.1@rikvax.riken.go.jp> you write:
#
#   Hello Folks,  
#
#  I have one question in migrating a simple assembler routine from VAX/
#VMS to Alpha/VMS.  In VAX/VMS, following assembler routine nargs.mar
#
#     .entry   nargs, ^m<>
#     movl    @8(sp),r0
#     ret
#     .end
#
#  can be used to determine the number of the arguments when the original
#routine (subroutine) was called.  For example,
#
#      call test(a1,a2,a3)
#      :
#      subroutine test(a1,a2,a3,a4,a5)
#      na=nargs()
#
#In this case, the above assembler nargs routine returns the values 3 in na, 
#because the subroutine test was called with three arguments, a1, a2 a3,  and
#the 8(SP) stores the saved Argument Pointer (AP) when the subroutine test was 
#called. 
#
# 
#  In Alpha/VMS, the above assembler routine dose not work. The assembler
#ended with error
#
#         movl    @8(sp),r0
#    ^
#    %AMAC-E-UPLEVSTK, up-level stack reference in routine NARGS
#    at line number 2 in file RIK$NP2:[ICHIHARA.TEST]A.MAR;4
#
#This may be natural. Because calling procedure may be different in
#VAX and Alpha architecture and SP may be virtualin Alpha.
#
#   The question is, How can I migrate this nargs.mar to Alpha/VMS ?
#

You can't due to the fact that the calling standard is different on the
Alpha.  However here is a program that will basically give you what you
want.  I make no guarantee as to its capabilities (just know it works
most of the time for me).

/*
 *	ALPHA_ARGCNT.C
 *
 *	This program can should return the number of arguments
 *	that a routine was called with.
 *
 *	WARNING: This will only work for Alpha/VMS systems
 */

#ifndef __ALPHA

#error "This code is only for OpenVMS AXP"

#else

extern void LIB$GET_CURRENT_INVO_CONTEXT();
extern int  LIB$GET_PREVIOUS_INVO_CONTEXT();

int ArgCnt()
{
	char context[560];	/* context block */
	int status;		/* status returned by LIB$ */

	/* get the context block for the call to this routine */

	LIB$GET_CURRENT_INVO_CONTEXT(&context[0]);

	/* Now get the context for the person who called us */

	status = LIB$GET_PREVIOUS_INVO_CONTEXT(&context[0]);

	/*
	 * if status is 1, return the least significant
	 * byte of the AI register.  Otherwise, return
	 * -1.
	 */

	return ((status & 1) ? context[527] : -1 );
}

#endif /* __ALPHA */


--
Patrick L. Mahan

--- TGV Window Washer ------------------------------- Mahan@TGV.COM ---------

Waking a person unnecessarily should not be considered  - Lazarus Long
a capital crime.  For a first offense, that is            From the Notebooks of
							  Lazarus Long


