Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assembly Language and Platform Independence

Tags:

assembly

I am confused regarding platform dependence. I would like to get this straight. So, if I understand it correctly, particular hardware architecture will have a particular instruction set.

Right? Eg. if we are talking about say Intel 8086 processor, then there is a specific instruction set for this processor. If I code in this instruction set it means that I am coding in the assembly language supported by Intel 8086. Right?

Now this particular processor architecture can be used by a variety of machines and operating systems. Eg. A MAC using Mountain Lion OSX, a Lenovo machine using Ubuntu as its OS and a Sony VAIO machine using Windows 7 as its OS, all of these machines can have their underlying processor architecture as Intel 8086. Right?

So now if I write code (to say add 2 numbers) in assembly language for Intel 8086 processor, this code should run without any problems on all the 3 machines mentioned above. And a common assembler should be able to convert this code to the machine level code on all these 3 machines. Right?

So now, where does platform dependence come into picture here? Since the asm code is being written for the same underlying processor architecture, should it not just run on all platforms?

I am just trying to figure out where am I going wrong and getting confused. What am I missing here? Please bear with me if the question sounds confusing or stupid.

like image 725
qre0ct Avatar asked Feb 02 '14 19:02

qre0ct


1 Answers

I'll give you a bad car analogy as to why there are problems.

Cars of all brands are constructed with screws and bolts of the same type (8086 code)

And although you can take a screw from a Ford (Windows) and screw it into a Toyota (OSX), you can't take a body panel from a Ford (Internet explorer) and bolt it onto a Toyota (OSX).

The panels may be attached with the same sorts of screws and bolts, but the panels will never fit between the two brands.

Thus while you can use the same fundamental instructions between Windows and OSX to build basic things, once you start building things in the style of the OS you can no longer interchange them. And that heads you down the road of platform dependence.

(I told you it would be a bad analogy)

like image 159
Peter M Avatar answered Nov 25 '22 13:11

Peter M