Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

clock cycles per instruction?
Goto page Previous  1, 2
 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
Goorman

Bascom Member



Joined: 12 Jul 2017
Posts: 13

PostPosted: Fri Jul 14, 2017 11:40 pm    Post subject: Reply with quote

'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
View user's profile
Evert :-)

Bascom Expert



Joined: 18 Feb 2005
Posts: 2156

netherlands.gif
PostPosted: Sat Jul 15, 2017 1:59 pm    Post subject: Reply with quote

Thanks for the numbers.
_________________
www.evertdekker.com Bascom code vault
Back to top
View user's profile Visit poster's website
Goorman

Bascom Member



Joined: 12 Jul 2017
Posts: 13

PostPosted: Sat Jul 15, 2017 10:46 pm    Post subject: Reply with quote

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
View user's profile
Evert :-)

Bascom Expert



Joined: 18 Feb 2005
Posts: 2156

netherlands.gif
PostPosted: Sat Jul 15, 2017 11:16 pm    Post subject: Reply with quote

Hi Goorman,

Some reading to do: http://www.atmel.com/Images/doc0936.pdf

_________________
www.evertdekker.com Bascom code vault
Back to top
View user's profile Visit poster's website
Goorman

Bascom Member



Joined: 12 Jul 2017
Posts: 13

PostPosted: Sun Jul 16, 2017 3:14 am    Post subject: Reply with quote

Evert Smile wrote:
Hi Goorman,

Some reading to do: http://www.atmel.com/Images/doc0936.pdf

Thank you for your response ٍEvert
Back to top
View user's profile
Per Svensson

Bascom Member



Joined: 03 Oct 2004
Posts: 235
Location: Gothenburg, Sweden

sweden.gif
PostPosted: Sun Jul 16, 2017 1:31 pm    Post subject: Reply with quote

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
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum