I understand that writing anything in assembly, or adding assembly to any program harms its portability. But, how bad? I mean, basically all PC's are x86 or x64 these days, right? So, if I embed assembly into a C program, why wouldn't it still compile no matter where it went?
Does this notion of un-portability just refer to when you really dig in to the specific quirks of a specific processor, to squeeze out every drop of performance from a piece of code?
The PC game "Roller Coaster Tycoon" was written almost entirely in assembly language if I remember correctly. So... How un-portably could it really be?
Is Assembly Language Portable? o A language whose source programs can be compiled and run on a wide variety of computer systems is said to be portable. C++ programs, for example. o Assembly language is not portable because it is designed for a specific processor family.
A portable assembly language provides access to machine-level features like memory addresses, ma- chine words, code addresses, and modulo arith- metics, like assembly language, but abstracts away differences between architectures like the assembly language syntax, instruction encoding, register set size, and addressing ...
The code which was written in c could be easily reused on a different platform, beside it Assembly does not provide the portability and source code specific to a processor because assembly instruction depends on the processor architecture. Software which has written in assembly perform well as compared to C.
A program written in assembly language consists of a series of mnemonic processor instructions and meta-statements (known variously as declarative operations, directives, pseudo-instructions, pseudo-operations and pseudo-ops), comments and data.
Besides the processor itself, there are, of course, always other considerations: what are the calling conventions on your target platform? How are struct
values passed to other (say: API) functions? Which registers may be clobbered by the callee? Which are guaranteed to be preserved for the caller? How to do a system call? What's the memory layout prepared for you by the OS upon process start?
Porting assembly, there is also the problem of the ABI, that varies from OS to OS. Porting a C program from Unix to Windows (or even from Linux to OpenBSD) may be a straightforward recompilation, but for an assembly program, you may find that some callee-save registers become caller-save, or that the floating-point parameters are passed differently.
And this is not only theoretical, viz. register r2 of the PowerPC versions of Linux and Mac OS X. In practice the problem may not be too bad, for instance AMD published a "recommended" ABI at the same time as its 64-bit instruction set.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With