I was looking at some old files and found these files containing MMIX assembly code.

The first file is a program for converting angles from a single value to sexagesimal notation, and back. The second file is a program for calculating the area of a triangle.

I have more MMIX code dating back at least 9 years, and some files are maybe close to 14 years old. I’ll see if I can manage to post those files too.

dec2dms.mms

* Two functions for converting an angle from a single unit value to
* degrees, arcminutes, and arcseconds, and back.

		LOC	#100

		PREFIX	:dec2dms:

dec		IS	$0
d		IS	$0
m		IS	$1
s		IS	$2
t		IS	$255

:dec2dms	FLOT	t,60		t = 60.0;
		SET	m,d		m = d;
		FINT	d,:ROUND_OFF,d	d = floor(d);
		FSUB	m,m,d		m -= d;
		FMUL	m,m,t		m *= t;
		SET	s,m	s = m;
		FINT	m,:ROUND_OFF,m	m = floor(m);
		FSUB	s,s,m		s -= m;
		FMUL	s,s,t		s *= t;
		POP	3,0		return (d, m, s);

		PREFIX :dms2dec:

d		IS	$0
m		IS	$1
s		IS	$2
dec		IS	$0
t		IS	$255

:dms2dec	FLOT	t,60		t = 60.0;
		FDIV	m,m,t		m /= t;
		FADD	dec,dec,m	dec += m;
		FMUL	t,t,t		t *= t;
		FDIV	s,s,t		s /= t;
		FADD	dec,dec,s	dec += s;
		POP	1,0		return dec;

		PREFIX	:Main:

argc		IS	$0
argv		IS	$1
h		IS	$2
arg1		IS	$3
arg2		IS	$4
arg3		IS	$5
t		IS	$255

:Main		FLOT	arg1,60		arg1 = 60.0;
		FLOT	arg2,36		arg2 = 36.0; arg3 = 0.0;
		PUSHJ	h,:dms2dec	h = dms2dec(arg1, arg2, arg3);
		SET	arg1,h		arg1 = h;
		PUSHJ	h,:dec2dms	(arg1, arg2, h) = dec2dms(arg1);
		SET	arg3,h		arg3 = h;
		PUSHJ	h,:dms2dec	h = dms2dec(arg1, arg2, arg3);
		SET	t,0		t = 0;
		TRAP	0,:Halt,0	_exit(t);

tri_area.mms

		LOC	#100

		PREFIX :tri_area:

a		IS	$0
b		IS	$1
c		IS	$2
s		IS	$3
t		IS	$255		Pseudocode in C:

:tri_area	FADD	s,a,b		s = a + b;
		FADD	s,s,c		s += c;
		FLOT	t,2		t = 2.0;
		FDIV	s,s,t		s /= t;
		FSUB	t,s,a		t = s - a;
		FMUL	a,s,t		a = s * t;
		FSUB	t,s,b		t = s - b;
		FMUL	a,a,t		a *= t;
		FSUB	t,s,c		t = s - c;
		FMUL	a,a,t		a *= t;
		FSQRT	a,a		a = sqrt(a);
		POP	1,0		return a;

		PREFIX :Main:

argc		IS	$0
argv		IS	$1
h		IS	$2
a		IS	$3
b		IS	$4
c		IS	$5
t		IS	$255

:Main		FLOT	a,12		a = 12.0;
		FLOT	b,15		b = 15.0;
		FLOT	c,20		c = 20.0;
		PUSHJ	h,:tri_area	h = tri_area(a, b, c);
		SET	t,0		t = 0;
		TRAP	0,:Halt,0	_exit(t);

* Register usage:
*
* +---------------------+------+------+----+----+----+----+----+-----+------+
* | In Main before call | argc | argv | h  | a  | b  | c  | ?  | ... | t    |
* |                     | $0   | $1   | $2 | $3 | $4 | $5 | ?  | ... | $255 |
* +---------------------+------+------+----+----+----+----+----+-----+------+
* | Inside tri_area     | ?    | ?    | ?  | a  | b  | c  | s  | ... | t    |
* |                     | ?    | ?    | ?  | $0 | $1 | $2 | $3 | ... | $255 |
* +---------------------+------+------+----+----+----+----+----+-----+------+
* | In Main after call  | argc | argv | h  | ?  | ?  | ?  | ?  | ... | t    |
* |                     | $0   | $1   | $2 | ?  | ?  | ?  | ?  | ... | $255 |
* +---------------------+------+------+----+----+----+----+----+-----+------+