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

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

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

3,289 次查看
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)
标签 (1)
0 项奖励
回复
3 回复数

1,048 次查看
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 项奖励
回复

1,048 次查看
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 项奖励
回复

1,048 次查看
muskut
Contributor I
thanks a lot for the answers. Nice points all
0 项奖励
回复