View previous topic :: View next topic |
Author |
Message |
Goorman
Joined: 12 Jul 2017 Posts: 13
|
Posted: Fri Jul 14, 2017 11:40 pm Post subject: |
|
|
'Bascom AVR 2.0.7.3
$regfile = "m32def.dat"
$crystal = 16000000
$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 10 ' default use 10 for the SW stack
$framesize = 40 ' default use 40 for the frame space
Dim A As Word , B As Word , C As Word
Dim E As Byte, F As Byte, G As Byte
Do
A = B / 100 '255 Cycles !
A = B / 1000 '255 Cycles!
A = B / C '31 Cycles
A = A / C '31 Cycles
A = A / A '31 Cycles
E = E / 100 '112 Cycles!!!!!!
E = F / G '111 Cycles !!!!!
E = E / F '111 Cycles !!!!
E = E / E '111 Cycles !!!!
Loop
End
The question is. Why Bascom needs 111 cycles to divide eight bits register?
Last edited by Goorman on Sat Jul 15, 2017 4:06 pm; edited 3 times in total |
|
Back to top |
|
|
Evert :-)
Joined: 18 Feb 2005 Posts: 2156
|
|
Back to top |
|
|
Goorman
Joined: 12 Jul 2017 Posts: 13
|
Posted: Sat Jul 15, 2017 10:46 pm Post subject: |
|
|
albertsm wrote: | there is no list. a lot of statements cycles depend on the context.
like : print somevar
it will matter what data type is.
then it also matters what kind of micro is used.
so there is no list, nor will there be one. use the simulator to count the cycles if it is that important.
of toggle some pin and measure with at scope. |
Hi
Why Bascom needs 111 cycles to divide eight bits register? |
|
Back to top |
|
|
Evert :-)
Joined: 18 Feb 2005 Posts: 2156
|
|
Back to top |
|
|
Goorman
Joined: 12 Jul 2017 Posts: 13
|
Posted: Sun Jul 16, 2017 3:14 am Post subject: |
|
|
Thank you for your response ٍEvert |
|
Back to top |
|
|
Per Svensson
Joined: 03 Oct 2004 Posts: 235 Location: Gothenburg, Sweden
|
Posted: Sun Jul 16, 2017 1:31 pm Post subject: |
|
|
The time and nr of cycles of a division depend strongly upon the data. If the reminder fast becomes zero as in 12/2 or 15/3 then few cycles are needed. If you divide by a constant and need fast and/or predictable divide time then try signed rightshift operator or combo of multiplication and shift. Also use as short data types as possible. Use word instead if integer for unsigned numbers, etc.
N*5 shifted 2 times right (N*5/4) is faster than N*1.25. etc.
There are more tricks for faster math, like truncated series and cordix.
Use google for more... |
|
Back to top |
|
|
|