Jump to content
Sign in to follow this  
Stringer

IF( bank != correct )

Recommended Posts

(I'm using PIC16F877)

 

I have this variable (notice the address):

_kirjoita_temp_UpdateX          equ 0x16d;1

 

I have given it a value as following:

	movlw D'254'
bcf STATUS, RP0
bsf STATUS, RP1
movwf _kirjoita_temp_UpdateX
;;;;;;;;{
;;;;;;;; char kirjoita_temp = 254;

 

Now when I compare it later to value 200 as following:

 

;;;;;;;; if( kirjoita_temp < 200 )
label_0096
movlw D'200'
subwf _kirjoita_temp_UpdateX, W
btfsc STATUS, C
goto label_0107
;;;;;;;; gotoX(kirjoita_temp);

 

It thinks that the IF clause is TRUE.

Why? I checked the STATUS register, and it looks like RP1:RP0=01, meaning that selected bank is Bank 1 (80h - FFh).

 

Is this bug in the compiler, or am I just imagining?

 

I must mention that I have a switch in between the variable initialization and the compare. Perhaps the compiler thinks that the bank is correct, because THERE is correct bank switching for the variable.

 

Following code is a simplified example when the problem occurs:

#include <system.h>

main()
{
  char first@0x00c9=200;
  char last@0x0016d=254;
  
  switch(first)
  {
     case 0:
        last=0;
        break;
     case 100:
        last=0;
        break;
     case 200:
        last=0;
        break;
     case 240:
        last=0;
        break;
  }
  
  if( last < 200 )
     asm nop;
     
  while(1);
}

 

Now the bright side here is that this bug comes only with maximal optimizations.

Share this post


Link to post
Share on other sites
Guest Pavel

Sorry I don't see any problem here. Code switches to the 'last" bank under the "case 200:" statement and when "if( last < 200 )" is reached the correct bank is already set. The execution flow also goes as it should and executes the "asm nop;" instruction. What makes you think there is an error?

 

Regards,

Pavel

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...