Need simple ASM division algorithm
Like the title says.
I tried making my own but I messed it up.
This code would work if it knew when to exit but it always·shifts in·extra junk after it accumulates the answer. I was trying to avoid a counter but I see that's not really possible.
What I'm aiming for is the least amount of ASM instructions used. Not the fastest execution time. I would also prefer that the result appear in the mathArgument variable.
Also, this algorithm doesn't really do what I want. I need to be able to divide two unsigned·32 bit numbers by each other. The results of those divisions will be in the 16 bit to 8 bit area.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
I tried making my own but I messed it up.
mov mathResult, #0 ' Setup.
shl mathArgument, #16 '
divideLoop if_nz shr mathArgument, #1 ' Preform division.
cmpsub sampleBuffer, mathArgument wc '
rcl mathResult, #1 '
tjnz mathArgument, #divideLoop '
sampleBuffer res 1
mathArugment res 1
mathResult res 1
This code would work if it knew when to exit but it always·shifts in·extra junk after it accumulates the answer. I was trying to avoid a counter but I see that's not really possible.
What I'm aiming for is the least amount of ASM instructions used. Not the fastest execution time. I would also prefer that the result appear in the mathArgument variable.
Also, this algorithm doesn't really do what I want. I need to be able to divide two unsigned·32 bit numbers by each other. The results of those divisions will be in the 16 bit to 8 bit area.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,

Comments
asmdivide32bit mov t1,#0 ' no idea mov t2,#32 ' multiply/divide :mdiv shr y,#1 wc,wz ' divide rcr t1,#1 if_nz djnz t2,#:mdiv :mdiv2 cmpsub x,t1 wc rcl y,#1 shr t1,#1 djnz t2,#:mdiv2 asmdivide32bit_ret retcalled like:
' divide SUM by SIZE_OF_ROLLING_AVG mov x,sum ' x mov y,RollingAvgSize ' y call #asmdivide32bit ' y = x/y mov sum, yJames