News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

data As Code may cause stack underflow?

Started by keytapper, Aug 19, 2022, 08:50 AM

Previous topic - Next topic

keytapper

Hello Boss,
I have some project to carry out, but I found some particular effect. Currently I'm trying my solution on the spot..
This is one example:
(* Simple test to convert a word binary value into a fixed position on a LCD.
 Then the leading zeros are substituted by spaces so the position will not move the
 decimal point because the string size is fixed as a 'DEC4 n,".",x' would.
 The method uses only five division
*)
Device = 16F877A
Xtal   20

Config FOSC_HS, WDTE_OFF, PWRTE_OFF, BOREN_ON, LVP_OFF, CPD_OFF, _
WRT_OFF, DEBUG_OFF, CP_OFF

' LCD assignment to a standard PORTB
Declare LCD_DTPort PORTB
Declare LCD_Interface 4
Declare LCD_RSPin PORTB.2
Declare LCD_ENPin PORTB.3
Declare LCD_Lines 2
Symbol NUMDGT 5                     ' For a word variable is this much
Symbol POINTPOS NUMDGT - 1          ' can be varied to a wanted position
Dim buff[NUMDGT + 2] As Byte        ' for 14bit core, no chances for strings
Dim alpha As Word
' array of divisor. So starting to divide the left most digit if any
Dim divisors As code = As Word 1,10,100,1000,10000
Dim ZERO_OUT As Code = As Byte "   0.0"   ' fixed answer for a zero input

Cls
alpha = 0
Do
' little test to see on the LCD
    Print At 1,1, "number is ", Dec alpha
    DisplayNum(alpha)
    Print At 2, 10, Str buff        ' result to the right hand side
    alpha = Random
    DelayMS 1000                    ' give time to read it
Loop

'==============================================================================
Proc DisplayNum(inval As Word)
  Dim PP2 As Byte System            ' system variable into the BASIC code
  Dim PP2H As Byte System           ' system variable into the BASIC code
  Dim wPP2 As PP2.Word              ' Collect the remainder of the division
  Dim var1 As Byte                  ' counter for right to left scan
  Dim var2 As Byte                  ' memory to the calculated digit into ASCII
  Dim bufpntr As Byte               ' pointer on the buffer
  Dim nonzero As Bit = 0            ' flag to set the first non zero occurance
  Clear buff                        ' empty before conversion
  Clear bufpntr                     ' left most position on the buffer
  If inval = 0 Then                 ' if value is zero skip calculate
   buff = ZERO_OUT                  ' default answer, including leading spaces
   ExitProc                         ' leave the process
  End If
  var1 = NUMDGT                     ' Starting from left most digit
  Repeat                            ' looping to the whole display size
    Dec var1                        ' highest digit
    ' divided for the wanted divisor
    var2 = inval / divisors[var1] + 48
    inval = wPP2                    ' remainder in the input value
    If nonzero = 0 Then             ' when still not set the first non zero digit
      If var2 = "0" Then            ' leading zero ?
        var2 = " "                  ' change it to a space
      Else
        Set nonzero                 ' otherwise set the first non zero occurance
      End If
    End If
    If bufpntr = POINTPOS Then      ' according to the wanted DP position
      buff[bufpntr] = "."           ' put the dot
      Inc bufpntr                   ' shift one position
    End If
    buff[bufpntr] = var2            ' ASCII on to the buffer
    Inc bufpntr                     '
  Until var1 <= 0                   ' Loop to completed the data
EndProc

The fact is the direct assignment (line 49) buff = "   0.0"will not get lost after the first call to __Read__TableData_
I remedied to move to the SRAM the two constants and that will be. So I'll get going.

I hope that I'm not stressing to much, but if so, I'm willing to pay and already tried to get a new package, unfortunately didn't success.
Ignorance comes with a cost

top204

#1
I've just ran your code in the latest Positron compiler and it compiles correctly, with no errors.

With the standard 14-bit core devices, they have a very small call stack, so routines that are too nested will cause the device's stack to overflow. Remember, that the devices also have very fragmented RAM, so arrays call a library routine to find out where each element of the array is in the RAM banks, and this adds to the stack as well. The compiler was the very first to allow arrays larger than the fragmented and small RAM bank sizes and this is because it called a library subroutine everytime an element is read or written, but it is not efficient. In fact, nothing can be efficient with the standard 14-bit core devices. :-)

Code memory reads also use a library subroutine call, because the data is placed as Retlw mnemoncs, and not actual flash memory directive, because not all standard 14-bit core devices support reading flash memory directly, so that also adds to the device's stack.

With standard 14-bit core device, place arrays at the beginning of the Dim list, so they can "maybe" stay in RAM bank 0, if they are not too large. This will allow the compiler to use the FSR and INDF SFRs to access the elements, because the array is in a single RAM bank

Again, as I keep saying..... The standard 14-bit core devices are now very, very outdated so they have a lot of limitations with all procedural languages, because everything uses the device's call stack.

An error message for a "stack underflow" is when the compiler's internal label or variable stack pointer has gone below what it should, and this can also be caused by too much nesting on the standard 14-bit core devices, but the above program does not generate that error message, and it is a very rare occurance indeed for that error message. I placed it in the compiler just to make sure nests were OK for myself.


keytapper

I did check how many nested level I'm using. I also adopted to reduce to the minimum. So the event is happening when the caller is at SP 2. I noticed that there are command that using two subroutine call. Well that is what I can see with the simulation. I could see that the first jump is completed.

I will check once more to see whether I got something incorrectly during that test. Yesterday I downgraded to my original version (3.7.5.4) because I wanted to understand what could have cause the problem with the Abs() command.

I just updated the compiler, but I got no results.
I'm getting to the point that I should live with this outdated MCU, as long as I keep them in use. I apologize to cause such a disturb, in facts the list might be updated and exclude certain mummies and the trouble that it would involve to maintain them.
Ignorance comes with a cost

top204

Keytapper... Asking questions about the old Proton compiler is not valid?

The Proton compiler is no longer valid, and the Positron8 compiler has had many added features and corrections applied to it, so any answers or checks by other users are meaningless. :-)

Even some of the code that is posted on here will not work in the old Proton compiler, because it may be using one of the new features added.

The updates are for the Positron compilers only, and are not valid on the old Proton compilers. They use different files, and all sorts of other things have changed on them.

keytapper

Quote from: top204 on Aug 19, 2022, 04:07 PMThe Proton compiler is no longer valid
I will take that in account. So I consider the fact that backward compatibility is a troublesome maintenance.
I feel sorry to have posed these arguments. I'll try to get rid of the obsoleted stocks.
QuoteThe updates are for the Positron compilers only, and are not valid on the old Proton compilers
Well, my original version was bought after the divorce  ;D. Shouldn't I entitled to apply the latest updates?
Ignorance comes with a cost

John Drew

@keytapper,
That's a bit tough and expecting too much for a developer to maintain obsolete software. Most software developers have an end date for their software and the proton compiler has reached that.
Kind regards,
John

keytapper

I agree to the point that obsolete MCUs shouldn't be mentioned. My apologies to have caused such discomfort. We are humans and, perhaps, a little aged, so I'm prone to oversights  :-[
 
Then I found my workaround and I will use just RAM variable, which are a bit faster. I admit that I went trough the matter why the compiler got the results without issuing a warning. I changed to a 16F1827 and tested.

So I was expecting that a statement like:
Dim divisors As Code = As Word 1,10,100,1000,10000
var2 = inval / divisors[var1] + 48
could be used. But the case is different, the value is not read as wanted.

The working version is like this:
alpha = LRead16 divisors[var1]
var2 = inval / alpha + 48
Both are compiled without warnings.
Perhaps I was expecting to address the variable in Flash with a similar manner I use to do with the RAM variables. Well, there's a difference and I was hopeful to make no such difference.
I admit I had upgraded the compiler for the latest, but I was using the wrong executable, left into the PDS directory. Yesterday I wipe out all the old files and I started a brand new installation. So I also noticed several new thing.
Ignorance comes with a cost

John Drew

All good keytapper and it's great you have a workaround.
John

Piero55

Hi,
I need clarification: I purchased the Positron Positron Compilers Setup license for- MY NAME - 4.0.0.9-1.1.0.4 in October 2021. I have not understood if it is no longer upgradeable. Now I got Update 4.0.2.4-1.1.0.9, does it update my Positron in full?
I use positron for hobbies and not for work. Sorry for my English, the result of a translator

top204

Quotedoes it update my Positron in full?

Yes.... If your compiler is "Positron", and not "Proton", the correction updates will work on it.

You can verify by pressing the F2 button after a succesful compilation in the IDE, and view the assembler code's header text. It will have the name of the compiler, and your ID name for the registration of it.





keytapper

#10
I'm standing for the potential buyers, a non professional person. Imagine that are looking on the list in order to make a decision on what would be worth the purchase.

Price is the winner over the competitors. There might be persons that by the misleading information (internet is the source of that) got started with these old MCU, then wanting a compiler that is smart enough to make fit their project. Then other compilers cannot challenge for that, I tested.

Here I admit my flaws that I was too superficial on the test. I, then would vote for a revision on the published list of what is intended to care of.
Ignorance comes with a cost

trastikata

Too much fuss for nothing.

The compiler is a masterpiece software which costs 50$ and I am pretty sure most of the people complaining or doubting about upgrades are spending this amount for completely useless things on a monthly basis. Hell, a pizza and a beer today cost about that.

If someone doesn't see the worth of paying 50$ for an upgrade, then he doesn't actually need it.

top204

#12
OK........ Enough is enough!

"If you do not like it do not buy it or use it" But do not expect to get consultation advice on the forum.

I spend a vast amount of time working on the compilers and trying to improve them and giving advice where I can! And what do I get out of all of that dedication? £33.00 from Ebay after they have ripped me off with their charges. And I get about two sales per month from the compiler!

If it progresses like this more, where people are actually complaining about rarely having to pay for something that has so much time and dedication put into it and has so much usefulness and professionalism put into it, and getting a consultation for "free" on the forum, I will need to take a good hard look at my foolishness and just call it a day!!!!! All it does is make my anxiety worse and makes me question my worthiness! Since my brain hemorage, I have tried my damnest to make myself feel worthy again, and try to correct the damage it caused in my brain with positive thinking, but then others simply push it to one side as if what I create is worthless and should be free to them, regardless of what it takes, or costs, to create it!.

Electricity if not free, and this forum is not free and my time could be spent trying to make a living instead of helping, so "why" should I give everything I have taken a lifetime to learn, and time to conceive of and create away for free all the time????

Is this really the world we live in now, where people expect "everything" for free? Except the crap they buy for hundreds or thousands of pounds so they can talk to people when they are outside! Or the expensive crap they buy to eat because the are too lazy to cook for themselves?


Many thanks trastikata, it is people like you that give me confidence in what I do.

Frizie

Come on Keytapper  ::)
You know as well as the others that $50 is a very low price for what the Positron PIC compiler offers you.
Les puts all his energy into this wonderful compiler, is very helpful but then he must be able to assume that we are working with the latest versions.

When I see your other comments and answers on the forum, you are always helpful, you have knowledge of the matter and I appreciate you very for this.
For this reason I had already assumed that you were already working with a fully updated Positron, also to continue to support Les  :P

And it's what Trastika already reported, a lot of people buy nonsense things for this amount that are gathering dust in a closet.
For this amount you have a compiler that you can enjoy for years to come  ;D
Ohm sweet Ohm | www.picbasic.nl

joesaliba

Quote from: Frizie on Aug 22, 2022, 08:56 AMFor this reason I had already assumed that you were already working with a fully updated Positron, also to continue to support Les

Frizie, I had the same assumption.

Keytapper,

Positron is a hobby of mine as well. What ought I to say? I got my copy back in 2005 mainly out of curiosity about how to programme a PIC and because I've always wanted to try coding, (not for £30.00, but £150.00), whether it be for PCs or PICs, despite having no formal education in the subject. I was able to do this thanks to Proton/Positron.

I work in a hotel, have had no job for a year and a half due to COVID, have a wife and two girls to support, and I still purchased the most recent edition since it was affordable, mainly to support Les in keeping up his excellent work.

Could I remained with Proton? Yes. But I did my small contribution by buying the full latest version. 

I wish I have a constant job and a decent living so I could make at least a yearly donation. However, as soon as the paid upgrade becomes available, I will at least, purchase that upgrade to make this small donation.

Les, please refrain from allowing isolated remarks to demotivate the stellar work you do.

Regards

Joe

Piero55

Quote from: top204 on Aug 21, 2022, 07:47 PM
Quotedoes it update my Positron in full?

Yes.... If your compiler is "Positron", and not "Proton", the correction updates will work on it.

You can verify by pressing the F2 button after a succesful compilation in the IDE, and view the assembler code's header text. It will have the name of the compiler, and your ID name for the registration of it.





Hi,
thanks for the clarification and congratulations for the Positron. With the characteristics of him I think that it will be very difficult for me to abandon him.
Regards
Peter-55

Rizwan s shaikh

#16
Halo
I'm tray to read 24 bit ADC NAU7802 please help me

top204

#17
The NAU7802 post is in the wrong thread Rizwan.

You need to set up a new thread for it in the Proton8 section of the forum.

Note to Myself...
I must change the names of the compilers on this forum, otherwise, it is getting confusing. The names "Proton" and "Proton24", no longer exist for the compilers. They are now "Positron8" and "Positron16". :-)

atomix

How about changing the domain for the forum to positroncompiler.com that's better for google searches.

top204

I cannot afford another domain name, or the attachement of another domain name to the original domain name. :-(

So it will need to stay named as "protoncompiler.com". It also allows less confusion when searching, because the Proton compiler's name is known, but I had no choice but to change it because I foolishly had trust, and I never registered the name "Proton" for myself!