Like Tree5Likes
  • 1 Post By laserlight
  • 1 Post By iMalc
  • 3 Post By ledow

When C was invented to be portable, were there many different types of CPUs in use?

This is a discussion on When C was invented to be portable, were there many different types of CPUs in use? within the C Programming forums, part of the General Programming Boards category; I don't get why people say assembly is not portable but it can work on any processor with a x86 ...

  1. #1
    Registered User
    Join Date
    Apr 2010
    Location
    Vancouver
    Posts
    117

    When C was invented to be portable, were there many different types of CPUs in use?

    I don't get why people say assembly is not portable but it can work on any processor with a x86 architecture (which is virtually all PCs). What was the purpose of inventing C if assembly is actually portable, was it back in the day there was a large variety of architectures in use?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,744
    I don't get why people don't search the Web for "history of C" when it can make for some pretty good reading
    Salem likes this.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,304
    FYI, all PCs produced recently are 64-bit. Sure, they run some x86 programs under emulation, but you can't mix x86 and x64 in the same program.
    Assemby also includes all of the SIMD variants of MMX, SSE 3DNOW etc, which various processors over history have implemented subsets of. It's easy to write assembly code that will run on one x86 CPU but not another. Or you can write code which will be fast on one CPU and slow on another. Heck some compiler writers may even do so intentionally.
    x86 Assemby itself isn't a single language either really. In particular if you talk about inline assembly, GCC has different syntax to say Visual Studio.

    And who ever said that the PC market was either the largest CPU market, or the most important? Other household devices such as your TV, washing machine, dishwasher, car etc all have CPUs, a lot of which are other platforms such as ARM. PCs are but one piece of the market. At work I write code for x86, x64, ARM, Motorola CPUs etc, and in the past I've done 680x0 assembly. Any one of those variants of assembly language will not run on the other.

    No, assembly is very much not portable! On the other hand I can write C code that can be used across all of them if I so wish.
    Salem likes this.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  4. #4
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    383
    When C was invented, x86 didn't even exist. In fact, Intel had existed for about a year when C was first developed. The 8086 (the first "x86" CPU) was invented several years before C was developed. C was created to make porting an OS (Unix, to be exact) from a PDP to other machines easier than trying to rewrite the original assembly-language source code every time it needs to be ported (the OS still had some assembly language as the "glue" between the bare hardware and the C abstract machine, but it was relatively little compared to the rest of the OS; this is still true of every OS today AFAIK). Have you ever written an assembly-language program for a PDP? Me neither. It's possible the same thing will be said about x86 in another 40 years, but C will most likely live on for decades, if not centuries, to come.

    Saying assembly language is portable in that it runs on any x86 CPU is like saying the Model T came in any color as long as it's black.

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    2,579
    FYP
    The 8086 (the first "x86" CPU) was invented several years after C was developed.
    Tim S.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

  6. #6
    Registered User ledow's Avatar
    Join Date
    Dec 2011
    Posts
    435
    Assembly isn't portable. Not to other architectures and not to other machines and not to other OS's. Try running an assembler-compiled executable on Linux and Windows, or even old Windows and new Windows. You won't be anywhere close to getting complete compatibility between the two. That's before you get into things like opening files (different on every OS and even versions of Windows), different instruction sets (SSE, MMX, etc. - use some instructions and you can quite easily get a program that runs on AMD and not Intel, even!), different processors entirely (x86 isn't even the most common chip in the world, the ARM is!).

    C was written precisely BECAUSE assembly isn't portable. It abstracts all those differences away into a compiler so you only have to have a C compiler written for your platform and everything else can be done in C code. And a C program from the 1960's written for a PDP-1 will, pretty much, compile and work the same on your modern GCC compilers (hell, you can still use K&R C, the original books on C with example programs, on modern C compilers). You might need an option or two switched on to compensate for changes in the C standard itself but on the whole it will compile, and the result will work on that machine (note: It does not even mean that that result will work on any other machine, though - only "C" itself is portable, the resulting binaries aren't!).

    Whereas, for example, a binary from assembler written on an old machine might not be written for the same processor at all (= instantly useless), might not know how to co-operate with the OS at all, might not even run on certain processors even if they are descendents of the original processor (just go looking for things like DOS utilities and try to run them in Windows 8, for example - or try to execute Pentium instructions on a 386), might not even know how to allocate memory properly.

    To think otherwise is to completely misunderstand what a programming language is and how it works. C is an abstraction so that ANY computer can have code written for it that (if written properly and to the C standard) can be made to work on any machine. Assembly is merely an antiquated and hardware-dependent mid-stage that is the RESULT of compiling C code. Literally, they operate on different layers. And assembly is inherently tied to the machine you compiled/wrote it for.
    Salem, stahta01 and hi_friends like this.

    - Compiler warnings are like "Bridge Out Ahead" warnings. DON'T just ignore them.
    - A compiler error is something SO stupid that the compiler genuinely can't carry on with its job. A compiler warning is the compiler saying "Well, that's bloody stupid but if you WANT to ignore me..." and carrying on.
    - The best debugging tool in the world is a bunch of printf()'s for everything important around the bits you think might be wrong.

  7. #7
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    383
    Quote Originally Posted by stahta01 View Post
    FYP

    The 8086 (the first "x86" CPU) was invented several years after C was developed.
    Tim S.
    You are correct, and that's what I meant. There was a disconnect between my brain and my typing fingers.

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,744
    Well, considering that you started with "when C was invented, x86 didn't even exist", your brain must have gotten disconnected after the full stop
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    383
    Quote Originally Posted by laserlight View Post
    Well, considering that you started with "when C was invented, x86 didn't even exist", your brain must have gotten disconnected after the full stop
    I think I swapped the operands in my mind (C < x86 vs x86 < C) due to the order of the two in the first sentence.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 04-28-2011, 01:27 PM
  2. What does the 32-bit in 32-bit CPUs Refer to?
    By jrahhali in forum Tech Board
    Replies: 13
    Last Post: 02-20-2011, 12:54 AM
  3. Dual Core CPUs
    By (TNT) in forum Tech Board
    Replies: 4
    Last Post: 12-27-2005, 09:18 AM
  4. Does Anybody Here Remember When Hanz Gubenstein Invented Time Travel?
    By LuckY in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 08-04-2005, 06:03 PM
  5. compiler using SMP (multiple CPUs)?
    By melmo in forum C++ Programming
    Replies: 7
    Last Post: 04-29-2004, 06:31 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21