UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

Reply

For loops does not count as intended.

Visitor
Posts: 6
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

Voyager
Posts: 869
Registered: ‎05-06-2012

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;

Visitor
Posts: 6
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.