简体   繁体   中英

Assembly code generated by different compilers?

I have started studying assembly for ARM arch. I read in some pdf files, and small tutorials in net . I understood the code there. But when i wrote a simple hello world program in GCC then it gave a assembly file whose contents looked very different from what i learnt in pdf and internet.(I mean mainly the assembly directives).

SO , it means that assembly code generated by different compilers is different(all use different way f writing the assembler directives and some other things). As what ever tutorial i read in internet i guess they were based on Kiel compiler.

If what i wrote above is true, Then according to which compiler shall i learn assembly language for ARM.

You should learn assembly according to the instruction set and architecture of the machine you have (and the directives according to the assembler you're using). Two of the principal reasons for learning assembly are to understand an instruction set, and to do things that just aren't possible in a higher-level language - looking at the subset of functionality that maps to that higher language isn't all that useful in either respect, even less so if compiler optimisation has transformed it beyond recognition. I'd say this is particularly true on ARM, where the instruction set can do all sorts of wacky things - it's quite a different paradigm from higher languages and best tackled on its own terms.

As you've noticed, looking at compiled output is good for learning how compilers work - different compilers with different optimisation strategies can sometimes end up implementing the same high-level code in very different ways.

That said, compiled code can be handy for the very basics like "what does this loop look like in assembly" - in which case the choice of compiler shouldn't matter at all since you'll want to keep things as simple as possible. That means disable all optimisations, stick to standard C (personally I'd even go for ANSI C over C99), and keep the code of interest in small separate functions so it's easier to make sense of the disassembly. Past the basics, though, this is less "learning assembly language" and more "learning about C in the context of assembly language".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM