;-----------------------------------------------------------------------------:
; 16bit/16bit Unsigned Division
;
; Register Variables
; Call: var1[1:0] = dividend (0x0000..0xffff)
; var2[1:0] = divisor (0x0001..0x7fff)
; mod[1:0] = <don't care>
; lc = <don't care> (high register must be allocated)
;
; Result:var1[1:0] = var1[1:0] / var2[1:0]
; var2[1:0] = <not changed>
; mod[1:0] = var1[1:0] % var2[1:0]
; lc = 0
;
; Size = 16 words
; Clock = 179..211 cycles (+ret)
; Stack = 0 byte
div16u: clr mod0 ;initialize variables
clr mod1 ; mod = 0;
ldi lc,16 ; lc = 16;
;---- calculating loop
lsl var10 ;var1 = var1 << 1;
rol var11 ;/
rol mod0 ;mod = mod << 1 + carry;
rol mod1 ;/
cp mod0,var20 ;if (mod => var2) {
cpc mod1,var21 ; mod -= var2; var1++;
brcs PC+4 ; }
inc var10 ;
sub mod0,var20 ;
sbc mod1,var21 ;/
dec lc ;if (--lc > 0)
brne PC-11 ; continue loop;
ret
| file: /techref/atmel/avr/div16x16sw-ec.htm, 1KB, , updated: 2007/9/14 17:14, local time: 2008/12/1 22:02,
38.103.63.58:LOG IN
|
| ©2008 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? Please DO link to this page! Digg it! <A HREF="http://www.piclist.com/techref/atmel/avr/div16x16sw-ec.htm"> Atmel AVR, atmega, Microcontroller, embedded controller, math, division, 16x16, elm-chan.org</A> |
| Did you find what you needed? |
|
o List host: MIT, Site host massmind.org, Top posters @20081201 Apptech, Jinx, Xiaofan Chen, olin piclist, Vitaliy, William \Chops\ Westfield, Tamas Rudnai, JonnyMac, Alan B. Pearce, Gerhard Fiedler, * Page Editors: James Newton, David Cary, and YOU! * Roman Black of Black Robotics donates from sales of Linistep stepper controller kits. * Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters. * Monthly Subscribers: Shultz Electronics, Timothy Weber, on-going support is MOST appreciated! * Contributors: Richard Seriani, Sr. |
|
.