cancel
Showing results for 
Search instead for 
Did you mean: 

STM8 Instruction Pipelining

evil_laugh
Associate
Posted on November 16, 2011 at 21:46

Hello everybody!

I've just got acquainted with STM8-L family and I'm already really fascinated. I have some questions though. Could anybody please help me?

I'm currently reading the document called '' CPU Programming Manual'', the chapter containing information about the pipelining of the controller.

Let's look at one of the first pages. It shows an example of the pipelining. I've marked the assembler commands with different colours for a better view.

0690X00000604y9QAA.png

We can see a few commands here. The first item I had to deal with, was how exactly is the number of CPU cycles for each command determined. It is divided into two parts: decode cycles and execute cycles. Let's look at the first command, LDW, here is its description from the same document.

0690X00000604yEQAQ.png

We can see, that this command takes 5 CPU cycles. And really, the first picture says it takes 4 cycles to decode and 1 to execute. 4 + 1 = 5, all clear.

Let's proceed to the next command, ADDW. Here's the decription.

0690X00000604yOQAQ.png

It says that this command should take 2 cycles! And here comes the question: why does the first picture say it takes 2 cycles to decode and 2 to execute? 2 + 2 = 4, isn't it?..

If we look at the next command (which, by the way, seems to have a syntax mistake) and compare its description with the first picture, we will see that the number of cycles is equal: 3 + 1 = 4.

0690X00000604vVQAQ.png

So please, could anybody tell me - where am I (or the datasheet) mistaken? It seems I do not understand, how is the number of cycles determined for the first picture and how does it correspond to the number of cycles determined in the commands' description. Help me, please! :)

2 REPLIES 2
mighel84
Associate II
Posted on November 18, 2011 at 14:57

I see something strange...

ADDW X, #20

ADDW X, #$1000

where is $ ended??? Do you know what it mean? I'm using C not assembly. I don't know...

As I could see ADDW is 1 byte for instruction and 2 for loading address data (or immediate) to be added.

It COULD be that the first clock of ''ADDW X, #20'' read command type. Second clock is to load from memory the first data byte (X is 16 bits), third clock load the second byte and begin sum calculation. Forth clock move in X the sum from ALU...

It's only ipotetical.

Finally: use C and let Compiler do it's job ahahah :)

evil_laugh
Associate
Posted on November 20, 2011 at 22:10

Hey there Michele!

Thanks for your answer.

$ - it's just a symbol showing a number in hexadecimal system, and # tells the assembler we are loading an exact number into the reg. So ADDW X, #$1000 just adds 1000 in hex to the X index register. Rather simple. And if there is no $ after the # symbol - then the number is in decimal format. ADDW X, #20 = add 20 in decimal to X.

Your suggestion is rather curious, I'll look closer into it. It seems I have to understand all these Fetch stages with their 64-bit and 32-bit buffers, etc... oh, so complicated :)

I'm just starting to work with these controllers and I think using ASM at first is going to help me o understand them better. I'll use C in the future ;) and, by the way, I simply like asm more than C :))