1: /*
   2:  * Copyright (c) 1987 Regents of the University of California.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  */
   6: 
   7: #ifdef LIBC_SCCS
   8:         <@(#)udiv.s	2.3 (Berkeley) 1/28/87\0>
   9:         .even
  10: #endif LIBC_SCCS
  11: 
  12: /*
  13:  * udiv(lhs::r0, rhs::r1)
  14:  *	unsigned	lhs, rhs;
  15:  *
  16:  * urem(lhs::r0, rhs::r1)
  17:  *	unsigned	lhs, rhs;
  18:  *
  19:  * Return unsigned div/rem and condition codes of result.
  20:  */
  21: #include "DEFS.h"
  22: 
  23: ASENTRY(udiv)
  24:         cmp     r1,$1           / if rhs > 1 && rhs < (2^16)/2 /*tricky*/
  25:         ble     9f              /   return ((unsigned long)lhs)/rhs
  26:         mov     r1,-(sp)
  27:         mov     r0,r1
  28:         clr     r0
  29:         div     (sp)+,r0
  30:         rts     pc
  31: 9:
  32:         bne     9f              / else if rhs == 1
  33:         tst     r0              /   return lhs
  34:         rts     pc
  35: 9:
  36:         cmp     r1,r0           / else if lhs < rhs
  37:         blos    9f              /   return 0
  38:         clr     r0
  39:         rts     pc
  40: 9:
  41:         mov     $1,r0           / else return 1
  42:         rts     pc
  43: 
  44: ASENTRY(urem)
  45:         cmp     r1,$1           / if rhs > 1 && rhs < (2^16)/2 /*tricky*/
  46:         ble     9f              /   return ((unsigned long)lhs)%rhs
  47:         mov     r1,-(sp)
  48:         mov     r0,r1
  49:         clr     r0
  50:         div     (sp)+,r0
  51:         mov     r1,r0           / (div leaves "%" in r1)
  52:         rts     pc
  53: 9:
  54:         bne     9f              / else if rhs == 1
  55:         clr     r0              /   return 0
  56:         rts     pc
  57: 9:
  58:         cmp     r0,r1           / else if lhs >= rhs
  59:         blo     9f              /   return lhs - rhs
  60:         sub     r1,r0
  61: 9:
  62:         tst     r0              / else return lhs
  63:         rts     pc

Defined functions

udiv defined in line 23; never used
urem defined in line 44; never used
Last modified: 1987-01-28
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2076
Valid CSS Valid XHTML 1.0 Strict