mikro C if command..teach me pleas...

Status
Not open for further replies.
In a Harvard architecture, the program and register space is in different memory maps, the program is NOT loaded into general purpose locations !

Quote from the MikroC help file:


Brian.
Can you explain it more clearly dear brian I mean then where does the program get loaded while burning to the controller if its not to the general memory locations?
Regards & thanking you.
Jerin.
 

maybe i need to re-phrase the question...
what's wrong with this?

#define counter 0x20

void main(void) {
asm {
clrf counter;
}
}
 

maybe i need to re-phrase the question...
what's wrong with this?

#define counter 0x20

void main(void) {
asm {
clrf counter;
}
}

Try with this code:

register counter = 0x20;

void main(void)
{
asm {
clrf counter;
}
}

Here register refers to the register storage class where mikroC stores variables within internal micro-controller memory.
So I think here 0x20 signifies that the location 0x20 of the general purpose memory is being accessed.
Regards,
Jerin. ;-)
 
But in HIGH TECH C ,
for(int i=0;i<=200;i++){//function//}
is working without any problem!!
 

In a Harvard architecture, there are at least two independent memories. One holds the program, the other holds the variables. Microchip share the variables space with internal peripherals so they can be read and written as though they were memory addresses. For example, in program memory space you can place instructions at address zero in the program memory but there is also a register zero in the variables memory, it is usually the indirect addressing register.

Quoting from the 16F84A data sheet although the others are the same:

Brian.
 

Yea, you can code in asm within the asm declaration block. In mikroBasic it's asm....end asm. In mikroC, I think it's like:
Code:
asm {
//.....block of assembly instructions
}
C comments (both single-line and multi-line) are allowed in embedded assembly code. Assembly-style comments starting with semicolon are not allowed.

If you plan to use a certain C variable in embedded assembly only, be sure to at least initialize it in C code; otherwise, linker will issue an error. This does not apply to predefined globals such as PORTB.

For example, the following code will not be compiled, as linker won’t be able to recognize variable myvar:
Code:
unsigned myvar;
void main() {
  asm {
    MOVLW 10  // just a test
    MOVLW test_main_global_myvar_1
  }
}
Adding the following line (or similar) above asm block would let linker know that variable is used:
Code:
myvar := 0;

Hope this helps.
Tahmid.
 
Last edited:

But in HIGH TECH C ,
for(int i=0;i<=200;i++){//function//}
is working without any problem!!

I didn't knew that. Actually it is possible to declare like that in C++ only. In C variable declaration should be either global i.e declared above the main function or local i.e inside a function. While declaring as local variable too,the above function should have been:

int i;
for(i=0;i<200;i++)
{
//code
}

Regards,
Jerin.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…