[wellylug]The top 10 dead (or dying) computer skills

Cliff Pratt enkidu at cliffp.com
Thu Jul 12 20:48:48 NZST 2007


Phillip Hutchings wrote:
> On 7/12/07, Cliff Pratt <enkidu at cliffp.com> wrote:
>> Phillip Hutchings wrote:
>> > On 7/11/07, Cliff Pratt <enkidu at cliffp.com> wrote:
>> >> nic wrote:
>> >> > And then there's DSP code, where _sometimes_ you want to get 
>> every last
>> >> > bit of performance out of a platform, and recoding an algorithm in
>> >> > assembler is the only practical option
>> >> >
>> >> > And porting a system to a new platform: you have to write the 
>> boot code
>> >> > in assembler, and you have to write the code create a C runtime
>> >> > environment in assembler.
>> >> >
>> >> You do not have to write in assembler to create either boot code or to
>> >> create a C runtime environment. You can do it in almost any language.
>> >
>> > When you're creating the first compiler for an entirely new platform
>> > you have to write _something_ in assembler. GCC won't magically output
>> > valid code for an unknown platform.
>> >
>> No. The way it is done is by cross-compiling. You write the code to
>> generate the new compiler on a convenient platform in a convenient
>> language and include the stuff to make it executable on the new system
>> and to allow it to create new executables on the new system. The
>> compiler is then transferred to the new platform. You don't *need* to go
>> to the assembler level, though for some routines it may be more
>> efficient at run time if you do so. And you need to know how to
>> interface with the system routines on the new platform.
>>
>> But you were talking about 'gcc'. The way to get 'gcc' to work on the
>> new platform is to amend the code of 'gcc' on a convenient platform, so
>> that it will create a valid executable for the new platform and create
>> correct binaries for the new code that it will generate and then compile
>> it (using the current version of the compiler for the compile platform).
>> The new version of the compiler will have the support for the new
>> platform. The binary of 'gcc' created is then transferred to the new
>> platform. Since you have compiled it as an executable for that system it
>> will run on that system and create valid executables for that system.
>>
>> So far as I am aware, gcc is written in C, isn't it?
> 
> So what you are saying is that you can make a compiler compile for a
> completely new platform without ever touching assembly? Ever?
> 
> Cross compiling or not, at some point you _WILL_ have to touch the raw
> metal, otherwise how does the compiler know that 1 + 2 needs to
> output:
> li    r3,1
> li    r4,2
> add    r5,r4,r3
> 
> to get 3 in r5 when no compiler is available? You can't write that in C.
>
You absolutely can! Tell me what the machine code is for that snippet on 
the target machine and I can code that as a variable! Then when that 
gets to the target machine it is the code. You can code *any* routine in 
C. The skill comes in making it relocatable and if necessary reusable.

What do you think assemblers are written in? Assembler? They are not. 
They are written in a higher level language.
 >
> For a quick overview look at
> http://le-hacker.org/hacks/projects/microprocessor/compiler.html, GCC
> outputs assembly when then gets shoved through the platform's
> assembler.
> 
> And yes, GCC is written in C now, but that's only because that once
> the compiler is capable of turning C in to assembly you can write C.
> Before then you need at least a basic compiler in assembly.
> 
No, not if you cross-compile it.

Cheers,

Cliff




More information about the wellylug mailing list