At 16:27 98.03.18 -0600, you wrote: >Hi, > >I was wondering whether there is any efficient way of implementing an >8-bit by 8-bit divide. My dividend is smaller than the divisor (always). >Both are positive numbers. The dividend is in the range 0-128 and the >divisor is in the range 0-256. The only way I know of is to implement it >as a 16-bit by 8-bit divide. But that takes 192 instructions which is a >lot for my application. > >Does anyone have any better idea how to do it? > >Thanks in advance, >Amey > Given the limitations that you mentioned, here you have a 8bit by 8bit division, that can divide up to 255 by 255 using a sucessive subtrtion algoritm. The operands are presented in op_a and op_b and the result in op_q and o p_r op_q = op_a DIV op_b (quotient) op_r = op_a MOD op_b (remainder) . . ; start ;op_a holds the divident ;op_b holds the divisor div8bit movlw .0 ; quotient <- 0 (zero) movwf op_q movf op_a,w ; remainder <- dividend movwf op_r div8bit_1 movf op_b,w subwf op_r,w ; remainder <- raminder - divisor btfss status,c ; result negative means remainder less than divi sor goto div8bit_2 ; yes - terminate discarding this last subtracti on movwf op_r ; no, save new remainder incf op_q,1 ; increment quotient goto div8bit_1 ; go on with next subtraction div8bit_2 ; finished ; op_a holds the divident ; op_b holds the divisor ; op_q holds tyhe quotient ; op_r holds the remainder . . this code fragment does not destroy the initial operands (dividend and divisor) If you can lose the them you can save a couple of instructions and one file position using the following code fragment . . ;op_a holds the divident ;op_b holds the divisor div8bit movlw .0 ; quotient <- 0 (zero) movwf op_q div8bit_1 movf op_b,w subwf op_a,w ; remainder <- remainder - divisor btfss status,c ; result negative means remainder less than divi sor goto div8bit_2 ; yes - terminate discarding this last subtracti on movwf op_a ; no, save new remainder incf op_q,1 ; increment quotient goto div8bit_1 ; go on with next subtraction div8bit_2 ; finished ; op_a holds the remainder (dividend destroyed) ; op_b holds the divisor ; op_q holds tyhe quotient . . =============================================================== cumprimentos / best regards Jorge Ferreira mailto://jorgegf@mail.telepac.pt ------ Make sure brain is in gear before engaging mouth ------- ===============================================================