[net.works] Assembly VS HOL: A

jans@mako.UUCP (Jan Steinman) (04/30/85)

Here's a short register dump routine.  It works fine on UTek (a Berklyoid),
but I don't have access to V or true 4.2.  It is probably non-portable to
those.  I wrote it in under an hour and it worked the first time.  I used
assembly because I couldn't figure out how to do it in C, but I don't claim to
be a seasoned C hacker.  Would others care to demonstrate HOL approaches to
the problem, preferably in a friendly, non-inflamitory manner?

To assemble on your favorite NS32000-based system:

	cpp dumpRegs.s | as -o dumpRegs.o

------------------------------ cut here --------------------------------------
/****	dumpRegs	******************************************************
*
* This is a simple register dump routine.  It accepts one parameter, which
* must be a pointer to a zero-terminated string.  It's return value is
* undefined: whatever was in R0 upon call.  All general-purpose registers are
* preserved.
*/
	.data
L_fmt:	.asciz "\t%s\n      r7       r6       r5       r4       r3       r2       r1       r0\n%8x %8x %8x %8x %8x %8x %8x %8x\n      fp       sp       sb     upsr\n%8X %8x %8x %8x\n\n"
	.text
	.globl _printf
	.globl _dumpRegs
_dumpRegs:
	sprd	 upsr,tos	/*Stack parameters in reverse order.	*/
	sprd	 sb,tos
	sprd	 sp,tos
	sprd	 fp,tos
	save	$0xff		/*Registers display in reverse order.	*/
	movd	 13*4(sp),tos	/*Stack the caller's message pointer,	*/
	addr	 L_fmt,tos	/*  and our "print" template.		*/
	jsr	 _printf	/*Print the stuff,			*/
	adjspb	$-2*4		/*  delete the string parameters,	*/
	restore	$0xff		/*  restore the genereal registers,	*/
	adjspb	$-4*4		/*  and delete the other parameters.	*/
	ret	$0		/*Caller must delete the msg pointer.	*/
-- 
:::::: Jan Steinman		Box 1000, MS 61-161	(w)503/685-2843 ::::::
:::::: tektronix!tekecs!jans	Wilsonville, OR 97070	(h)503/657-7703 ::::::

mat@amdahl.UUCP (Mike Taylor) (05/03/85)

> Here's a short register dump routine.  It works fine on UTek (a Berklyoid),
> but I don't have access to V or true 4.2.  It is probably non-portable to
> those.  I wrote it in under an hour and it worked the first time.  I used
> assembly because I couldn't figure out how to do it in C, but I don't claim to
> be a seasoned C hacker.  Would others care to demonstrate HOL approaches to
> the problem, preferably in a friendly, non-inflamitory manner?
> 
> To assemble on your favorite NS32000-based system:
> 

The following routine steals registers off the stack on my system (Amdahl)
in C. It isn't much more portable than yours, though.
I don't have an NS32000 and I didn't finish the job, but it's similar,
and it seems to work.

regs(message)
char *message;
{
        struct r {
        int regval[6];
        } rinst;
	char *format = "\t%s\n       r14      r13      r12      r10      r9       r8       \n%8x %8x %8x %8x %8x %8x\n";
        int *point;
        point = &rinst ;
	point = point + 14;   /* this is a cheat */
        printf(format,message,point->regval[5],
                              point->regval[4],
                              point->regval[3],
                              point->regval[2],
                              point->regval[1],
                              point->regval[0]);
}
-- 
Mike Taylor                        ...!{ihnp4,hplabs,amd,sun}!amdahl!mat

[ This may not reflect my opinion, let alone anyone else's.  ]