128k program memory ERROR

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
skartalov
Posts: 37
Joined: Fri Apr 09, 2010 10:50 am
Location: BULGARIA

128k program memory ERROR

Post by skartalov » Wed Mar 06, 2013 3:45 pm

Hi,

when I try to compiler program, larger than 64K, the compiler hangs up, saying nothing, just stop compilling, no HEX file generated.

I use 18F47J13, which has 128k of prog mem.
Please check? Why it could be?

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 » Wed Mar 06, 2013 6:08 pm

You will need to email me your complete project for me to investigate...

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 » Wed Mar 06, 2013 6:18 pm

I should add I also need the compiler version you are using and if it is the SE or full version. In either case, I assume you are running the latest compiler software?

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 » Thu Mar 07, 2013 9:16 am

Thanks for sending me your program. I built it using version 2.2.1.6 of the compiler, which took about 30 seconds on a lowly 2.8 GHz Pentium with just 1GB of RAM. I am quite happy with this performance, given the size of your program. I noticed in your email you are using version 2.2.1.0 of the compiler. Notice:

http://www.sfcompiler.co.uk/wiki/pmwiki ... ionHistory

version 2.2.1.5 introduced much improved compile times on large projects. I would urge anyone that notices a compiler problem to ensure they are using the latest version of the compiler before reporting an issue.

skartalov
Posts: 37
Joined: Fri Apr 09, 2010 10:50 am
Location: BULGARIA

Post by skartalov » Fri Mar 08, 2013 10:46 am

Now I use 2.2.1.6 version.

Large program compiles ok.
It is now 98kb, BUT still problems:


There are external data base named:

"rife.bas" -> these are names of the deseases (STRING constant)
"rife_freq.bas" -> the corresponding frequency (LONGWORD constant)
"oledfont" -> Character set for displayng on OLED (BYTE Coonstant)

Now, look at this video:

https://vimeo.com/61333740

This includes are at the following order:

include "oledfont"
include "rife_freq.bas"
include "rife.bas"

As you can see after Pr. 269 the names on the last display line disappears, even after moment, the program execution hangs, this is because the names file "rife.bas" is at last order.

If I put the "fire_freq.bas" to be the last include, than the program shows all name correctly, but after some position the frequency list becomes unavailable.

If I put "oledfont.bas" to be the last include, than the display do not show any characters correctly.

In all the cases the compiles generate *.HEX file, with no complains.

Clearly there is a bug in compiler, I suspect it cannot compile correct more than 64k useful code.

If I use smaller database, and the compiled code is 50k, everything works fine.

PICMicro used -> PIC18F47J13

Please, someone help!

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 » Fri Mar 08, 2013 11:07 am

It may be because you constants exceed the first 64K ROM. I would perhaps think about writing a routine that manipulates the ROM address manually to get access to the constants.

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 » Fri Mar 08, 2013 11:30 am

Also, perhaps watch out with using strings - there are 23 char + 0 in size by default. If using strings longer than this, you will need to dimension them correctly.

Jerry Messina
Swordfish Developer
Posts: 1469
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Post by Jerry Messina » Fri Mar 08, 2013 12:31 pm

>Clearly there is a bug in compiler, I suspect it cannot compile correct more than 64k useful code.

I use it with code sizes pushing 120K, so it does work (87K22)

But, I don't have > 64K of const data.

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 » Fri Mar 08, 2013 12:53 pm

The compiler places all constant data in lower ROM, before any program data. If it extends into the next 64K block, it can cause problems for the in-built routines to handle. However, it is very easy to work around this. Here is an example:

Code: Select all

Include "usart.bas"
Include "convert.bas"

const SIZE_ARRAY = 5 
Const cname(SIZE_ARRAY) As String = (
   "Oranges",
   "Apples",
   "Melon",
   "Pear",
   "Lots of grapes!"
)
// maximum string size of single array element - including
// the null terminator
Const STR_SIZE = sizeof(cname) / SIZE_ARRAY

// get a name by index, uses 24 bit address... 
Function name(index As Word) As String(STR_SIZE)
   Dim addr As LongWord
   
   // get address + offset, then load 24 bit address...
   addr = AddressOf(cname)           // address of constant string array
   addr = addr + (index * STR_SIZE)  // add the offset
   TBLPTRU = addr.Byte2  
   TBLPTRH = addr.Byte1
   TBLPTRL = addr.Byte0 
   
   ' now read the string...
   FSR0 = AddressOf(result)
   Repeat
      Asm
      TBLRD *+
      End Asm
      POSTINC0 = TABLAT
   Until TABLAT = 0 // look for null terminator
   TBLPTRU = 0      // reset upper 8 bits!!... 
End Function

// main program...
SetBaudrate(br19200)
Usart.Write("name = ", name(4), 13,10)
You are basically replacing a "name(index)" array access with a function call. You wont need to rewrite your main code block - just add a public function like the above to your constants file and make the constant itself private.

skartalov
Posts: 37
Joined: Fri Apr 09, 2010 10:50 am
Location: BULGARIA

Post by skartalov » Fri Mar 08, 2013 1:48 pm

Now this solution worked!
Thanks a lot!

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 » Fri Mar 08, 2013 2:15 pm

Great, thanks for letting us know. Don't forget, Swordfish will lay down array constants before any code and in the order encountered. For example,

include "int_constants.bas"
include "string_constants.bas"

will generate int_constants before string constants. If you swap them around, the ints may end up beyond 64K and you will need to use the above code technique on the int constants as well.

Post Reply