Compiler and temporary variables ...

Discuss about beta versions of mikroPascal compiler.
Post Reply
Author
Message
yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

Compiler and temporary variables ...

#1 Post by yo2lio » 10 Feb 2008 16:45

Hello,

Take a look at this short example (P18) : :evil:

Code: Select all

program test_pt;

var addr1,addr2,addr3 : word;
    val1 : string[10]; absolute 300;
    val2 : string[10]; absolute 400;
    val3 : string[10]; absolute 500;
    
procedure get_addr(var dat1 : string[10]; var dat2 : string[10]; var dat3 : string[10]);
begin
  addr1 := @dat1;
  addr2 := @dat2;
  addr3 := @dat3;
end;

begin
  get_addr(val1,val2,val3); // addr1 = 300; addr2 = 400; addr3 = 500; OK !
  get_addr('123','456','789'); // addr1 = 27; addr2 = 27; addr3 = 27; Wrong values addr2 and addr3
end.
When I try to use get_addr routine in this manner :

Code: Select all

  get_addr('123','456','789');
compiler put my data in the same temporary local variables ! :oops: :oops: :oops:

Code: Select all

;test_pointer.ppas,17 :: 			get_addr('123','456','789'); // addr1 = 27; addr2 = 27; addr3 = 27;
$003E	$0E31	    			MOVLW	49
$0040	$6E1B	    			MOVWF	?main_Local_Text+0, 0
$0042	$0E32	    			MOVLW	50
$0044	$6E1C	    			MOVWF	?main_Local_Text+1, 0
$0046	$0E33	    			MOVLW	51
$0048	$6E1D	    			MOVWF	?main_Local_Text+2, 0
$004A	$6A1E	    			CLRF	?main_Local_Text+3, 0
$004C	$0E1B	    			MOVLW	?main_Local_Text
$004E	$6E1F	    			MOVWF	FARG_get_addr, 0
$0050	$0E00	    			MOVLW	@?main_Local_Text
$0052	$6E20	    			MOVWF	FARG_get_addr+1, 0
$0054	$0E34	    			MOVLW	52
$0056	$6E1B	    			MOVWF	?main_Local_Text+0, 0
$0058	$0E35	    			MOVLW	53
$005A	$6E1C	    			MOVWF	?main_Local_Text+1, 0
$005C	$0E36	    			MOVLW	54
$005E	$6E1D	    			MOVWF	?main_Local_Text+2, 0
$0060	$6A1E	    			CLRF	?main_Local_Text+3, 0
$0062	$C01F	F021			MOVFF	FARG_get_addr, FARG_get_addr+2
$0066	$C020	F022			MOVFF	FARG_get_addr+1, FARG_get_addr+3
$006A	$0E37	    			MOVLW	55
$006C	$6E1B	    			MOVWF	?main_Local_Text+0, 0
$006E	$0E38	    			MOVLW	56
$0070	$6E1C	    			MOVWF	?main_Local_Text+1, 0
$0072	$0E39	    			MOVLW	57
$0074	$6E1D	    			MOVWF	?main_Local_Text+2, 0
$0076	$6A1E	    			CLRF	?main_Local_Text+3, 0
$0078	$C01F	F023			MOVFF	FARG_get_addr, FARG_get_addr+4
$007C	$C020	F024			MOVFF	FARG_get_addr+1, FARG_get_addr+5
$0080	$EC04	F000			CALL	_get_addr
For Zoran : BTW , I drink also BECK'S !
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

User avatar
zristic
mikroElektronika team
Posts: 6608
Joined: 03 Aug 2004 12:59
Contact:

Re: Compiler and temporary variables ...

#2 Post by zristic » 11 Feb 2008 09:36

Hi Florin,

It has already been reported (just can't find the link).
The resolution is to use three text variables, to assign them the values and then to pass them to the procedure. It is illegal to pass a const string to var parameter, but we allow that in order to decrease the amount of code beginners need to write. The side effect is the problem you found.

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

#3 Post by yo2lio » 11 Feb 2008 14:47

Thank you very much Zoran .
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

Post Reply

Return to “mikroPascal Beta testing”