Why do I have to use an absolute variable in the IF statement?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Why do I have to use an absolute variable in the IF statement?

2,617 Views
muskut
Contributor I
an example code;

...
if var1 == 5
jmp label1
else
jmp label2
endif
...

My question is when I use a variable (like var1) there is no problem if the variable is absolute. But if the variable is relocatable I have got an error message which is "complex relocatable expression not supported". Why do I have to use an absolute variable in the IF statement? (my MCU is RS08)
Labels (1)
0 Kudos
3 Replies

376 Views
rocco
Senior Contributor II
Hi, Mustafa:

I believe the IF statements in that context are conditional assembly statements, not program statements. But I'm not sure, because I don't know what programs you are using, and which program generated the error.

Assuming the context is assembly language, and not Basic or some other language then those statements mean the following:
If the address defined for 'var1' is equal to 5 then compile the assembler instruction 'jmp label1' into the object file, otherwise compile the assembler instruction 'jmp label2' into the object file.
So the only code that is generated is a single 'jmp' instruction, probably to label2.

The reason for the error is that, if 'var1' is relocatable, it doesn't yet have an address to test against. When the assembler evaluates 'var1==5', it realizes that 'var1' is not yet equal to anything, and generates an error.
0 Kudos

376 Views
peg
Senior Contributor IV

Hi Mustafa,

I believe rocco is on the right track here.

The important thing is that the value of the variable (var1 in your example) must be known to the assembler at assemble time.

And the other short answer is.....

Because the manual says so!

Regards David

 

Message Edited by peg on 2006-08-10 08:54 PM

0 Kudos

376 Views
muskut
Contributor I
thanks a lot for the answers. Nice points all
0 Kudos