cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Visitor
Visitor
8,049 Views
Registered: ‎02-23-2015

For loops does not count as intended.

I have built my own Microblaze configuration using EDK 14.7. The Mircoblaze runs on a Spartan 3 model xc3s1000 on a Digilent starter board rev E. The Microblaze I setup to use the onboard SRAM as extra data memory. After the Microblaze configuration I have exported the hardware to SDK. In SDK I have started a C project. In my C project my program did not behave like intended. The program is:

#include <stdio.h>

#include "platform.h"

#include "xparameters.h"

int main()

{

                             init_platform();

                             int i = 0, j = 0;

                             for(i=0; i <100; i++)

                             {

                                                          j++;

                             }

                             return 0;

}

Here the “for loop” does not count right, as you can see on the picture below from the debugger where the variable j count faster than i.  So far I am aware i and j should follow in count. Does anyone have a clue about what is happing here?

for_not_working.png

Here is a link to the hardware design rapport: https://www.dropbox.com/sh/469my3l253mjrcv/AACk8c5TbR-E7dQhQDQB0PsRa?dl=0

0 Kudos
2 Replies
Highlighted
Anonymous
Not applicable
8,028 Views

Re: For loops does not count as intended.

You have a for loop that does nothing. The compiler will optimize it.
Try change the int j =0; to volatile int j = 0;

0 Kudos
Highlighted
Visitor
Visitor
8,020 Views
Registered: ‎02-23-2015

Re: For loops does not count as intended.

The loop does something? It counts a variable? 

 

I have also seen that when it checks the statement of a while-loop, it counts the variable up in the statement. 

 

We have tried to use volatile, it worked for some time, but them stopped again, when the code got longer and more complicated. 

0 Kudos