Forum > Embedded
light pascal
MarkMLl:
--- Quote ---The King then read from his book: "Rule forty-two. _All persons more
than a mile high to leave the court_."
--- End quote ---
Non-insiders should give precedence to "Alice in Wonderland" which has been around rather longer :-)
MarkMLl
devport:
OK, I came to some conclusions without having to get rid of system.pas files etc.
The use of STR in the program increases the size by an average of 4kB !!! (at least that's how I observe)
Using the string variable in function passing increases the result code by ~ 800B once. I must use VAR (reference) reduce the amount of generated code.
In general, I come to the conclusion that most of the optimizations should be kept on my side, not the compiler. So the compiler does as I command it.
marcov:
Note that such growth tapers off quickly once all language string helper have been used.
Any way, it is hard to suggest anything since you don't explain what exactly you need it for.
devport:
I have written a similar program in C for uC Cortex-M0. And my point is that in Pascal I haven't even achieved half of the functionality, and I'm already exceeding 5kB Flash more than the one written in C.
It worries me very much
I am slowly beginning to come to the conclusion that Pascal is not suitable for writing in microcontrollers.
:(
I have big problems writing in this language ... I do the same thing as in C, and yet I encounter Hard Fault more often than I did in C.
For example:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function Int_To_Str(buf : PChar; x : smallint):word;var buff : array[0..5] of char; p : PChar; size : longint; value : smallint;begin Result := 0; p := @buff; value := x; size := longint(buf); if(value < 0) then begin buf^ := '-'; Inc(buf); value := -value; end; if(value = 0) then begin buf^ := '0'; Inc(buf); exit; end; while(value > 0) do begin p^ := char(value mod 10 + Ord('0')); value := value div 10; inc(p); end; while p <> @buff do begin dec(p); buf^ := p^; inc(buf); end; size := longint(buf)- size; Result := word(size);end;
If Call where
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var st : string;begin Int_To_Str(@st, 20); end.
i get Hard Fault in line " buf^ := p^ "
Any attempt to write to 'buf ^' results in an error.
In C compiller this function it works.
STR I don't want to use because it weighs a lot :/ and requires heapmgr.pas (more kB)
MiR:
I think you are on the right track now, if you really want to bring down code size you have to check your every move and it's costs.
Strings are very expensive both as ansistrings (possible for e.g. arm, mips targets), there you will in most cases need to add heapmgr (Hint! Hint!) to make them properly work and the code for handling them is quite complex (--> big)
and also as shortstrings (avr) where they consume 256 bytes of precious ram on your stack for every function call that uses strings. Take a look at a function that concats two strings and returns the result, and while doing that say goodbye to 768 bytes of precious stack....
Also, for example using classes also increases code size, they need heapmgr and precious RAM is also used by VMT's when virtual methods are used.
The list goes on, when you want to keep codesize down you need to always check the generated assembler code and prepare for surprises :)
The question I always ask myself is WHY people today choose severely cpu and memory limited chips for freepascal...
I can understand it from the educational aspect, you learn a lot when trying to squeeze complex code into 32kb of Flash, but how many of the people using such a small system actually want to go through this learning curve?
There are quite capable and cheap boards out there in the sub-10$ range that offer 64-128kb of flash (look for STM32F103C8T6 or maple mini) and come with a stlinkv2 compatible debugger, there are even more capable boards with STM32F4 Chips (search for STM32F411CEU6) with 128kb RAM and 512kb Flash or ATSAMD21 Boards like Arduino-Zero or clones.
Thoses Chipsets eat through most of the limitations that come with todays freepascal, they have enough flash for some not so optimized code and they have enough CPU power to easily execute the complex string methods in freepascal.
Please do not misunderstand me, I like the smell of freshly generated assembler output of fpc, but I ask myself does everybody want to start that hard?
One could argue that AVR chips and older Arm Chips are easier to understand because of less complexity, but is this really true?
Me, I do not think so, you can also start simple with newer arm or mips chips, but there's a lot more (like DMA, advanced timers) that comes in handy once you have mastered the basics and start with the more challenging stuff.
But until that point you have already had a lot of fun with blinking LED's, OLED-Displays or whatever without hitting the out of RAM/Flash-Memory wall even once.
Michael
Navigation
[0] Message Index
[#] Next page
[*] Previous page