Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
04/18/05 16:55
Modified:
  04/18/05 16:59

Read: times


 
#91854 - Re:
Responding to: ???'s previous message
If r3=0 then 16bit/8bit division



;Maths Subroutines for the 8051 microcontroller
;subroutine UDIV16
;16-Bit / 16-Bit to 16-Bit Quotient & Remainder Unsigned Divide
;input: r1, r0 = Dividend X
;r3, r2 = Divisor Y
; output: r1, r0 = quotient Q of division Q = X / Y
; r3, r2 = remainder
; alters: acc, B, dpl, dph, r4, r5, r6, r7, flags
UDIV16: mov r7, #0 ; clear partial remainder
mov r6, #0
mov B, #16 ; set loop count

div_loop: clr C ; clear carry flag
mov a, r0 ; shift the highest bit of
rlc a ; the dividend into...
mov r0, a
mov a, r1
rlc a
mov r1, a
mov a, r6 ; ... the lowest bit of the
rlc a ; partial remainder
mov r6, a
mov a, r7
rlc a
mov r7, a
mov a, r6 ; trial subtract divisor
clr C ; from partial remainder
subb a, r2
mov dpl, a
mov a, r7
subb a, r3
mov dph, a
cpl C ; complement external borrow
jnc div_1 ; update partial remainder if
; borrow
mov r7, dph ; update partial remainder
mov r6, dpl
div_1: mov a, r4 ; shift result bit into partial
rlc a ; quotient
mov r4, a
mov a, r5
rlc a
mov r5, a
djnz B, div_loop
mov a, r5 ; put quotient in r0, and r1
mov r1, a
mov a, r4
mov r0, a
mov a, r7 ; get remainder, saved before the
mov r3, a ; last subtraction
mov a, r6
mov r2, a
ret


List of 20 messages in thread
TopicAuthorDate
16bit by 8bit divide            01/01/70 00:00      
   Check This!            01/01/70 00:00      
      And This:            01/01/70 00:00      
   16bit by 8bit divide            01/01/70 00:00      
      Re:            01/01/70 00:00      
         16bit by 8bit divide            01/01/70 00:00      
            To Thelam:            01/01/70 00:00      
   well, if you look a bit to the left            01/01/70 00:00      
   16bit by 8bit divide            01/01/70 00:00      
   Its just ben done            01/01/70 00:00      
   Non-iterative Division            01/01/70 00:00      
   Accuracy            01/01/70 00:00      
   No wonder            01/01/70 00:00      
   again and again            01/01/70 00:00      
   Efficient Division            01/01/70 00:00      
   the divide may ne the tip of the iceberg            01/01/70 00:00      
      16bit by 8bit divide            01/01/70 00:00      
         the Titanic hit the iceberg            01/01/70 00:00      
            16bit by 8bit divide            01/01/70 00:00      
   Don't know if it helps.            01/01/70 00:00      

Back to Subject List