please dont rip this site

Atmel AVR Microcontroller Basic Math Code Library

Divide 8 by 8 in software by http://www.avr-asm-tutorial.net

;
; 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
;
.CSEG
.ORG 0
;
	rjmp start
;
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
;
div8:
	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
;
div8a:
	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
div8b:
	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
div8c:
	clc      ; clear carry-bit, resulting bit is a 0
div8d:
	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
stop:
	rjmp stop   ; endless loop

©2002 by http://www.avr-asm-tutorial.net


file: /Techref/atmel/avr/div8x8sw-aat.htm, 2KB, , updated: 2007/9/14 17:14, local time: 2024/11/25 10:03,
TOP NEW HELP FIND: 
18.116.85.108:LOG IN

 ©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="http://massmind.org/techref/atmel/avr/div8x8sw-aat.htm"> 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?

 

Welcome to massmind.org!

 

Welcome to massmind.org!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .