please dont rip this site

Atmel AVR Microcontroller Basic Math Code Library

Divide 8 by 8 in software by

; Registers
.DEF rd1l = R0 ; LSB 16-bit-number to be divided
.DEF rd1h = R1 ; MSB 16-bit-number to be divided
.DEF rd1u = R2 ; interim register
.DEF rd2  = R3 ; 8-bit-number to divide with
.DEF rel  = R4 ; LSB result
.DEF reh  = R5 ; MSB result
.DEF rmp  = R16; multipurpose register for loading
.ORG 0
	rjmp start
; Load the test numbers to the appropriate registers
	ldi rmp,0xAA ; 0xAAAA to be divided
	mov rd1h,rmp
	mov rd1l,rmp
	ldi rmp,0x55 ; 0x55 to be divided with
	mov rd2,rmp
; Divide rd1h:rd1l by rd2
	clr rd1u ; clear interim register
	clr reh  ; clear result (the result registers
	clr rel  ; are also used to count to 16 for the
	inc rel  ; division steps, is set to 1 at start)
; Here the division loop starts
	clc      ; clear carry-bit
	rol rd1l ; rotate the next-upper bit of the number
	rol rd1h ; to the interim register (multiply by 2)
	rol rd1u
	brcs div8b ; a one has rolled left, so subtract
	cp rd1u,rd2 ; Division result 1 or 0?
	brcs div8c  ; jump over subtraction, if smaller
	sub rd1u,rd2; subtract number to divide with
	sec      ; set carry-bit, result is a 1
	rjmp div8d  ; jump to shift of the result bit
	clc      ; clear carry-bit, resulting bit is a 0
	rol rel  ; rotate carry-bit into result registers
	rol reh
	brcc div8a  ; as long as zero rotate out of the result
	            ; registers: go on with the division loop
; End of the division reached
	rjmp stop   ; endless loop

©2002 by

file: /Techref/atmel/avr/div8x8sw-aat.htm, 2KB, , updated: 2007/9/14 18:14, local time: 2024/6/21 12:58,

 ©2024 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! / MAKE!

<A HREF=""> Atmel AVR, atmega, Microcontroller, embedded controller, math, division</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.

Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

  PICList 2024 contributors:
o List host: MIT, Site host, Top posters @none found
- 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: Gregg Rew. on-going support is MOST appreciated!
* Contributors: Richard Seriani, Sr.

Welcome to!