xref: /original-bsd/lib/libc/mips/net/htonl.s (revision c3e32dec)
1/*-
2 * Copyright (c) 1991, 1993
3 *	The Regents of the University of California.  All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Ralph Campbell.
7 *
8 * %sccs.include.redist.c%
9 */
10
11#include <machine/machAsmDefs.h>
12
13#if defined(LIBC_SCCS) && !defined(lint)
14	ASMSTR("@(#)htonl.s	8.1 (Berkeley) 06/04/93")
15#endif /* LIBC_SCCS and not lint */
16
17/*
18 * netorder = htonl(hostorder)
19 * hostorder = ntohl(netorder)
20 */
21NLEAF(htonl)				# a0 = 0x11223344, return 0x44332211
22ALEAF(ntohl)
23#ifdef MIPSEL
24	srl	v1, a0, 24		# v1 = 0x00000011
25	sll	v0, a0, 24		# v0 = 0x44000000
26	or	v0, v0, v1
27	and	v1, a0, 0xff00
28	sll	v1, v1, 8		# v1 = 0x00330000
29	or	v0, v0, v1
30	srl	v1, a0, 8
31	and	v1, v1, 0xff00		# v1 = 0x00002200
32	or	v0, v0, v1
33#else
34#ifdef MIPSEB
35	move	v0, a0
36#else
37	ERROR
38#endif
39#endif
40	j	ra
41END(htonl)
42