Variable initialisation

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
Doj
Posts: 362
Joined: Wed Apr 11, 2007 10:18 pm
Location: East Sussex

Variable initialisation

Post by Doj » Mon Sep 03, 2007 2:30 am

I have four variables named, temp_left, temp_right, temp_top, temp_bottom.

when I use them:-

Code: Select all

    temp_left=LEFT_START                            'remember last positions
    temp_right=RIGHT_END
    temp_top=TOP_START
    temp_bottom=BOTTOM_END

'A ROUTINE GOES HERE<<<<<<<<<<<<<<<<<<<<

'JUMP TO ANOTHER ROUTINE IN MODULE<<<<<<<<<<<<<<<<<<

    LEFT_START=temp_left                            'restore last positions
    RIGHT_END=temp_right
    TOP_START=temp_top
    BOTTOM_END=temp_bottom

When I compile get a warning "Variable "LEFT_START" might not have been initialised, and for the other three the same.
If I comment out the first four and leave the second four in place the warning changes to "Variable "temp_left" might not have been initialised, and for the other three the same.

If I comment out both the above sets of lines the compiler then tells me every other instance of these variables may not be initialised.

If I comment the shown instances of the lines out and the "'JUMP TO ANOTHER ROUTINE IN MODULE<<<<<<<<<<<<<<<<<<" call the compiler does not give and warnings at all(and the routine obviously does not work).

I am also getting a complete crash on the compiler or IDE when I call a routine and do not know if this is the cause or a symptom the crash happens every time, if I comment out the call it just produces the warning.

The crash reports "Swordfish IDE" , "Access violation at address 004A514B in module `SwordfishIDE.exe`. Read of address 00000000".
The compiler shows the green arrow at the bottom left of the IDE screen with "Compiling, please wait..." and just sits there, the only way to shut it off is to right click on the task bar and choose close.
When you start it back up the "Compiling, please wait..." is still there until you do a sucessful compile.

User avatar
Steven
BETA Tester
Posts: 406
Joined: Tue Oct 03, 2006 8:32 pm
Location: Cumbria, UK

Post by Steven » Mon Sep 03, 2007 6:09 am

Could you post your complete code?

Steve

Doj
Posts: 362
Joined: Wed Apr 11, 2007 10:18 pm
Location: East Sussex

Post by Doj » Mon Sep 03, 2007 11:23 am

Hello Steven,
I can not post all the code as it is commercial, but I would be happy to send it on email.

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Post by David Barker » Mon Sep 03, 2007 12:09 pm

If you can email me the code I'll take a look at the exception...

Doj
Posts: 362
Joined: Wed Apr 11, 2007 10:18 pm
Location: East Sussex

Post by Doj » Mon Sep 03, 2007 1:01 pm

I have found out how to get rid of the initialisation warning, the trouble appeared to be that I was using variables that had not being given any values before it was encountered in code, giving the "LEFT_START" etc initial values in my main code cleared that warning.

Now testing the access violation.

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Post by David Barker » Mon Sep 03, 2007 1:12 pm

> I have found out how to get rid of the initialisation warning,
> the trouble appeared to be that I was using variables that
> had not being given any values

The warnings are there to help you and look correct, given the code posted. For example,

temp_left=LEFT_START

will generate a warning because you program has not initialised LEFT_START. It could be any value at startup, so the assignment is a little redundant. Providing you have initialised LEFT_START before it is used on the right hand side of an expression, you should not see any warnings.

Doj
Posts: 362
Joined: Wed Apr 11, 2007 10:18 pm
Location: East Sussex

Post by Doj » Mon Sep 03, 2007 2:37 pm

Ok on the initialisation, all sorted out now.

I have managed to compress the access violation to the following code, it is part of a much bigger program and these are the parts that are taken from that in order to demonstrate the problem, the real code is not like this.

The violation occurs if the routine "phone_ok" is un-commented.

Code: Select all

 Device=18f67J11
    
    
    Public Const phone_ok_high(246) As Byte=
    (4,198,4,198,4,198,4,198,4,198,4,198,4,198,4,198,
    4,198,4,198,4,198,4,198,4,198,4,198,4,198,4,198,
    4,198,4,198,4,198,4,198,4,198,4,198,4,198,4,198,
    4,198,4,198,4,198,4,198,4,198,4,198,4,198,4,198,
    4,198,4,198,4,198,4,198,4,0,4,198,4,198,4,198,
    4,198,4,198,4,198,4,198,4,198,4,198,4,198,4,0,
    4,198,4,198,4,198,4,198,4,198,4,198,4,198,4,0,
    4,198,4,198,4,198,4,198,4,198,4,0,4,198,4,198,
    4,198,4,198,4,0,4,198,4,198,4,198,4,198,4,0,
    7,0,4,198,4,198,4,198,4,0,7,0,4,198,4,198,
    4,198,4,0,7,0,7,0,4,198,4,198,4,0,7,0,
    7,0,4,198,4,198,4,0,7,0,7,0,4,198,4,198,
    0,7,0,7,0,7,0,4,198,4,0,7,0,7,0,7,
    0,4,198,4,0,7,0,7,0,7,0,7,0,4,198,4,
    0,7,0,7,0,7,0,4,0,7,0,7,0,4,0,7,
    0,4,0,4,0,4)
        
'****************************************************************************** 

'******************************************************************************
Public Const phone_ok_low(246) As Byte=
    (31,24,31,24,31,24,31,24,31,24,31,24,31,24,31,24,
    31,24,31,24,31,24,31,24,31,24,31,24,31,24,31,24,
    31,24,31,24,31,24,31,24,31,24,31,24,31,24,31,24,
    31,24,31,24,31,24,31,24,31,24,31,24,31,24,31,24,
    31,24,31,24,31,24,31,24,31,0,31,24,31,24,31,24,
    31,24,31,24,31,24,31,24,31,24,31,24,31,24,31,0,
    31,24,31,24,31,24,31,24,31,24,31,24,31,24,31,0,
    31,24,31,24,31,24,31,24,31,24,31,0,31,24,31,24,
    31,24,31,24,31,0,31,24,31,24,31,24,31,24,31,0,
    224,0,31,24,31,24,31,24,31,0,224,0,31,24,31,24,
    31,24,31,0,224,0,224,0,31,24,31,24,31,0,224,0,
    224,0,31,24,31,24,31,0,224,0,224,0,31,24,31,24,
    0,224,0,224,0,224,0,31,24,31,0,224,0,224,0,224,
    0,31,24,31,0,224,0,224,0,224,0,224,0,31,24,31,
    0,224,0,224,0,224,0,31,0,224,0,224,0,31,0,224,
    0,31,0,31,0,31)
    
'****************************************************************************** 

'******************************************************************************
Public Const phone_ok_steps(246) As Byte=
    (47,4,32,1,32,1,26,3,3,1,28,1,3,1,28,1,
    3,1,23,2,3,1,3,1,24,1,3,1,3,1,24,1,
    3,1,3,1,20,2,2,1,3,1,3,1,21,1,2,1,
    3,1,3,1,18,1,2,1,2,1,3,1,2,1,19,1,
    2,1,2,1,2,1,2,1,17,1,2,1,1,1,2,1,
    2,1,2,1,4,1,2,1,2,1,2,1,1,1,2,1,
    9,1,2,1,4,1,2,1,2,1,2,1,2,1,2,1,
    16,1,2,1,3,1,2,1,2,1,2,3,13,1,3,1,
    3,1,2,1,4,4,12,1,4,1,3,1,2,2,1,2,
    2,2,12,1,4,1,3,1,3,2,4,2,12,1,4,1,
    3,1,1,2,3,1,2,2,12,1,4,1,3,2,3,3,
    2,2,12,1,4,1,2,2,2,3,4,2,12,1,4,3,
    2,2,1,3,1,2,2,12,1,7,2,4,1,1,1,2,
    2,12,1,7,2,2,1,1,1,1,1,1,2,13,6,2,
    2,2,1,1,1,1,2,23,2,2,1,1,2,25,2,2,
    2,27,4,29,2,9)

'****************************************************************************** 

'******************************************************************************
    
    Dim steps_loop As Word
    Dim steps As Word
    Dim loop_1 As Word
    Dim current_steps As Byte
    Dim display_high As Byte
    Dim display_low As Byte
    
{
****************************************************************************
* Name    : CReadByte                                                      *
* Purpose : Return the data at requested memory address                    *
****************************************************************************
}
Public Function CReadByte(PAddress As TABLEPTR) As TABLAT
     ASM
     Clrf EECON1
     Bsf EECON1,EEPGD,0	
     Tblrd*+
     End ASM
End Function
    

Public Sub phone_ok()                                           'subroutine to call for printing to screen
    display_high=0
    display_low=0

    'READ THE NUMBER OF REPEAT STEPS FROM THE "STEPS" CData TABLE AND 
    'USE THE LOOP AS INDEX FOR THE LOW AND HIGH BYTE DATA TABLES.
    '##################################
    For steps_loop = 0 To steps                       'number of loop in the steps file
        current_steps=CReadByte(@phone_ok_steps+steps_loop)     'read number of steps to use in current screen write
        display_high=CReadByte(@phone_ok_high_byte+steps_loop)       'read the high byte value using the steps position
        display_low=CReadByte(@phone_ok_low_byte+steps_loop)         'read the low byte value using the steps position

        loop_1 = 0                                        'clear the loop counter

        'High (RS)                                         'select RS for data writing
        'Low (CS)                                          'enable display data port

        While loop_1 < current_steps
            'DISPLAY = display_high                        'load the data on the port
            'WR = 0                                   'initiate WRITE
            'WR = 1                                   'release WRITE line
            'DISPLAY = display_low                         'load the data on the port
            'WR = 0                                   'initiate WRITE
            'WR = 1                                   'release WRITE line
            Inc (loop_1)
        Wend

    Next

    'High (CS)                                         'disable display data port
    'Low (RS)                                          'idle RS low after this routine
    '##################################
    
End Sub

'IF THIS LINE IS NOT COMMENTED OUT THE ACCESS VIOLATION HAPPENS EACH COMPILE
'phone_ok
The CReadbyte code was sent to me by Tim ages ago but this is the first time I have tried it.
I am sure it is very simple but I am stuck now and do not know what to do.

Doj
Posts: 362
Joined: Wed Apr 11, 2007 10:18 pm
Location: East Sussex

Post by Doj » Mon Sep 03, 2007 6:23 pm

I have now found that if I comment out the "display_high=CReadByte....." and "display_low=CReadByte....." the IDE does not crash but produces an dASM error "Symbol not previously defined(EEPGD), (I wish we could copy from the results line!)

So I expect if that is sorted the crash will go away, the error may be being missed or misinterpreted in some way?

Doj
Posts: 362
Joined: Wed Apr 11, 2007 10:18 pm
Location: East Sussex

Post by Doj » Mon Sep 03, 2007 6:37 pm

The 18F67J11 does not have the register EEPGD as it does not have an EEPROM, so that is an obvious problem!

All the examples I have seen(Wikii) use this register and my poor old J11 does not have one!, EECON1.7(EEPGD) does not exist I am afraid.

HELPPPPPP!!!!!

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Post by David Barker » Mon Sep 03, 2007 7:22 pm

The exception is being caused because 'phone_ok_high_byte' and 'phone_ok_low_byte' have not been declared. It should be 'phone_ok_high' and 'phone_ok_low' - you have a _byte appended to them both.

Of course, the IDE should not crash at all - so I'll fix that for the next release. At least it's an easy workaround ;-)

You need to look at the datasheet for the 67J11 regarding table reads, but it looks fairly straight forward

Code: Select all

     ASM
     Tblrd*+
     End ASM
should work, but I've only taken a quick look so it's worth double checking. If you plan to go over 64K, don't forget to set TBLPTRU before the read and clear after reading.

Doj
Posts: 362
Joined: Wed Apr 11, 2007 10:18 pm
Location: East Sussex

Post by Doj » Mon Sep 03, 2007 8:17 pm

Thanks David, I will try it now and get back, mmm perils of converting code from PDS, the VB code I wrote to make the CDATA file in PDS calls it _byte and it is obviously transparent to me after looking at it for 6 months.
Lets hope things will be less hastle when it(the project) starts on the compiler it is going to finish.

Its good to know we all get less stupid each day!
Last edited by Doj on Mon Sep 03, 2007 8:29 pm, edited 1 time in total.

Doj
Posts: 362
Joined: Wed Apr 11, 2007 10:18 pm
Location: East Sussex

Post by Doj » Mon Sep 03, 2007 8:28 pm

It is with the greatest pleasure that I can say, IT WORKS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

That is a big hurdle for me, thanks for the help, its just the beginning.

Post Reply