xref: /original-bsd/lib/libc/mips/net/htons.s (revision dc4562f1)
1/*-
2 * Copyright (c) 1991 The Regents of the University of California.
3 * 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("@(#)htons.s	5.4 (Berkeley) 07/26/92")
15#endif /* LIBC_SCCS and not lint */
16
17#include <machine/endian.h>
18#undef	htons
19#undef	ntohs
20
21/*
22 * netorder = htons(hostorder)
23 * hostorder = ntohs(netorder)
24 */
25LEAF(htons)
26ALEAF(ntohs)
27#if BYTE_ORDER == LITTLE_ENDIAN
28	srl	v0, a0, 8
29	and	v0, v0, 0xff
30	sll	v1, a0, 8
31	and	v1, v1, 0xff00
32	or	v0, v0, v1
33#else
34#if BYTE_ORDER == BIG_ENDIAN
35	move	v0, a0
36#else
37	ERROR
38#endif
39#endif
40	j	ra
41END(htons)
42