The Natural Philosopher writes:
> On 23/04/18 10:59, Richard Kettlewell wrote:
>> The Natural Philosopher writes:
>>
>>> On 23/04/18 09:55, jack4747@gmail.com wrote:
>>>> Il giorno lunedì 23 aprile 2018 10:16:01 UTC+2, Gordon Henderson ha
scritto:
>>>>
>>>>> I have looked at compiling my BASIC to native code - and there is more
>>>>> or less a 1:1 relationship with a line of BASIC and a Line/Block of ASM
>>>>> - it's no-where near efficient as C though (and 'compiling' BASIC into
>>>>> C is just as easy and may actually result in faster code, but that's a
>>>>> job for another day)
>>>>
>>>> It's not that C is inherently efficient, it's the compiler that
>>>> optimize the asm.
>>>> If you compile a C source code with optimization disabled, you'll
>>>> get a (almost) 1:1 relationship line of C : line of asm.
>>>
>>> I think that is only half of it: The other half is that C IS
>>> assembler, written in shorthand. I cannot offhand think of any native
>>> c operation that is not an atomic assembler operation.
>>>
>>> Ok sometimes on some processors operation on the contents of memory
>>> are two opcodes.
>>
>> ! compiles to two instructions on ARM
>
> really!
>
>> and three on x86, in
>
> surely if in a conditional statment its just a reversal of the
> condition..I suppose you mean assignment like "a=!a" ...
Yes, or a function that just wraps it. Not always very useful but it
illustrates that even conceptually simple operators don’t directly
reflect single assembler instructions.
>> The prevalence of undefined behavior in C also punches a rather large
>> hole in any assumption of a direct mapping into assembler.
>
> Again that doesn't make sense. You can still map to assembler direct:
> the questions is WHAT assembler you map to...and what it does.
>
> I.e. deferencing a null pointer maps straight to assembler allright,
> but what happens is what is undefined - seg fault, random number or
> whatever happens to be a memory location zero..
CVE-2009-1897 is a famous example. A comparison compiled to _no_
assembler instructions, due to the context in which it appeared, thereby
introducing a vulnerability. Merely re-ordering a couple of statements
would have produced the “expected” assembler, illustrating that the
relationship between C and assembler is not direct but actually can be
highly contextual.
--
https://www.greenend.org.uk/rjk/
--- SoupGate-Win32 v1.05
* Origin: Agency HUB, Dunedin - New Zealand | FidoUsenet Gateway (3:770/3)
|