From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,23a17bbd96d53327 X-Google-Attributes: gid103376,public From: "news.oxy.com" Subject: Re: Assembler in Ada? Date: 1999/01/25 Message-ID: <78hvth$m36$1@remarQ.com> X-Deja-AN: 436692391 References: <369C5E08.69727537@mbox5.swipnet.se> <78a32f$dbr$1@remarQ.com> <78fvjm$82t$1@nnrp1.dejanews.com> X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 X-Complaints-To: newsabuse@remarQ.com X-Trace: 917275377 HXI3FRZSOA57FC7F8C usenet77.supernews.com Organization: Posted via RemarQ, http://www.remarQ.com - Discussions start here! Newsgroups: comp.lang.ada Date: 1999-01-25T00:00:00+00:00 List-Id: I have a feeling that the very idea of my two small examples was not understood at all. I should mention that I am not surprised at all - reading other Robert Dewar discussions (in particular in "brackets war") I expected something like this. First of all my examples were not intended to illustrate good programming style in assembler with GNAT. It is a big separate topic. Their aim were to explain how to understand what has been written in Machine Code Insertion Section of the GNAT reference manual (that probably is not very clear for some people without appropriate examples) and trying to be simple and short as possible. So these examples should be considered from only that point of view. First you need to explain meaning of what is being said in the manual as simple as possible and only after that you may give an examples of good style assembler with GNAT (These are very, very different tasks and sometimes require completely different approaches). Neither of that has been done in GNAT documentation. It sounds very funny to hear from people who did not do something (intentionally or not) that someone, who filled that gap, did not do it very good. It is better to say thanks that this has been done and make necessary improvements in documentation and provide further better examples. I consider this forum as the place where people can help each other, share their knowledge and experiences and are not trying to use it to argue that they are the best, the cleverest, the most bright minds which are always right. For that we may set up another discussion thread. See my other comments below. dewar@gnat.com wrote in message <78fvjm$82t$1@nnrp1.dejanews.com>... >In article <78a32f$dbr$1@remarQ.com>, >> Asm ( >> "movl %1, %%eax" & nl & -- note nl > >This is a bad idea, use one Asm call per instruction. If some person states that something is bad that does not mean all the times that it is bad in reality. I agree that it is not very convenient to insert "nl" to construct Asm string template. This should be done by GNAT itself !! (e.g. using array of strings for Asm call template instead if single string template or have proper interpretation of multi line assembler code in Asm procedure call). This is again one of the weak sides of the GNAT that needs to be improved. Just look at the Borland Delphi and some other systems how this is done. Everything is handled properly for multi-line Asm insertions. Everything is very simple. Everything is very well documented. No need for any kind of "nl" things. Moreover, one Asm call per instruction is not convenient as you need to construct several Asm calls to pass you parameters in and out so I do not consider that as good and productive approach. Do what is more convinient for users and not for ACT. >Also you probably do NOT want to use an explicit register >here. It is allowed, but it usually at the wrong level. >It is true one does this more on the ia32 than other >machines, but it is poor as an example. Wrong, wrong and again wrong. If anyone goes down to assembler level , he/she does this to get direct access to processor registers and set of operations that can be performed on them and machine memory otherwise there is no need to go down to such low level. Do things at the higher level. I just wanted to show how to use registers and that this is possible. Example from the GNAT reference manual with one Asm instruction does not give the slightest idea about that. Usually assembler programming is done for very specific things for which translator can not generate efficient machine code and this is done by people who know why they are using assembler. After Intel starts production of the "Merced" chip which has 128 general purpose registers and 128 floating point registers there will be new generation of the compilers that will use that registers very efficiently for bigger size procedures written in high level languages. After that the need for the assembler code insertion will be much less than now. Only for extremely specific things. Those who will be the first will have advantage on the market. >You do not need to set the clobbers argument in this case >to %%eax, it won't cause trouble to do so, but there is no >need, and in an example it is confusing. Again, this is just an example how to preserve registers that will be spoiled by the Asm code and nothing more. Usually you do not need to preserve eax at all. There are two ways to preserve registers: - by Asm code itself or by using clobbers. Each one may be more convenient in different circumstances. >> False -- compiler, do not optimise my code > >It is quite wrong to mark this as volatile, this is not >a volatile instruction. Again, this is just an example how to say translator not to try to improve your code and nothing more. There is no need to go into deep details. >> From the last example you can see that it is necessary to >> be very careful when >> manually controlling passing varaibles to the registers. > >It is generally a bad idea to write asm code at this level >(a level where you rely on detailed knowledge of the ABI >for passing parameters), and it is not necessary. Again, it was no more than example that shows how it is possible to pass parameters via registers and it is not covered by GNAT documentation. Do not take it more seriously. More generally if you are doing assembler coding you know why you do this. If you passing parameters via registers you know why you are doing that. This is for what assembler is used. One thing that I did not mentioned earlier is that then you are using Asm calls then you loose portability become ties to the specific processor thus loosing Ada program portability for different hardware platforms. >Once again, we recommend that anyone interested in using >this feature read the documentation in the GCC manual. The >design of the ASM feature in Ada has been chosen to be a >very thin binding to the corresponding C feature, so that >documentation and examples apply without any confusion. Again, include this manual or part of it in GNAT public distribution. See the rule mentioned in the previous messages regarding this issue. Make GNAT more comfortable for users. Regards to all, Vladimir Olensky (vladimir_olensky@yahoo.com) (Vladimir_Olensky@oxy.com) Telecommunication specialist, Occidental C.I.S. Service, Inc. ( www.oxy.com ) Moscow, Russia.