⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 div16u.s

📁 ICCAVR中所有的库函数源码
💻 S
字号:
; "div16u" - 16/16 Bit Unsigned Division
;
; This subroutine divides the two 16-bit numbers 
; r17:r16 (dividend) and r19:r18 (divisor). 
; The result is placed in r17:r16 and the remainder in r15:r14
; Low registers used  :2 (r15:r14)
; High registers used :5 (r16,r17,r18,r19,r24)

  .text
mod16u::
  set
  rjmp  xdiv16u
div16u::  
  clt
xdiv16u::
  st    -y,R14
  st    -y,R15
  st    -y,r24
  clr   r14       ; clear remainder
  clr   r15
  ldi   r24,16    ; init loop counter
d16u_1:
  lsl   r16       ; shift dividend/quotient left
  rol   r17
  rol   r14       ; shift dividend into remainder
  rol   r15
  cp    r14,r18   ; remainder <= divisor?
  cpc   r15,r19
  brcs  d16u_2    ; skip if >
  sub   r14,r18   ; remainder -= divisor
  sbc   r15,r19
  inc   r16       ; quotient++, lsb = 0
d16u_2:
  dec   r24       ; decrement counter
  brne  d16u_1    ; if not done
  brtc  nocopy    ; if T is set, then copy the remainder R14/15 to R16/17
  mov   r16,r14
  mov   r17,r15
nocopy:
  ld r24,Y+
  ld R15,Y+
  ld R14,Y+
  ret

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -