www.pudn.com > iccavr_lib.rar > div8s.s, change:2003-11-08,size:844b


	.text
;   div8s   - 8/8 Bit Signed Division

; This subroutine divides two signed 8 bit numbers 
; r16 (dividend) and r17 (divisor). 
; The result is placed in r16.
; The remainder is the result if mod is called.

; Low registers used   :2 (r14,r15)
; High registers used  :3 (r16,r17,r18)

mod8s::
  st    -y,r14
  set
  mov   r14,r16   ; move dividend to sign register
  rjmp xdiv8s
div8s::  
  st    -y,r14
  clt
  mov   r14,r16   ; move dividend to sign register
  eor   r14,r17   ; xor divisor with sign register
xdiv8s:
  sbrc  r16,7     ; if MSB in dividend set
  neg   r16       ; change sign of dividend
  sbrc  r17,7     ; if MSB in divisor set
  neg   r17       ; change sign of divisor
  rcall xdiv8u    ; do the divide
  sbrc  r14,7     ; if MSB in sign register set
  neg   r16       ; change sign of result
  ld    R14,Y+
  ret