Won't Be Coming Back
Posts: 1,822
Threads: 200
Joined: 2009-10
How is a program (C, C++, binary?) able to affect change the properties of a processor? In other words, how do words and letters typed into an interface cause (electricity?, magnetism?, wave signals?) to move within the tiny pieces of metal that make up a computer? Say that there are pieces of metal and no computers exist. How would a processor be built, how would it be worked (manual switches?), and how would it give an output?
Oh and as a side question, how does an infinite loop destroy the pieces of metal that make up the processor, or cause them to malfunction (in terms of physical processes) so that they are forever destroyed or unusable?
Posting Freak
Posts: 6,092
Threads: 186
Joined: 2008-07
I assume you're thinking of overclocking?
Basically, as I understand, it goes through two stages:
Now I haven't taken any class on this subject so I'm just replying for the sake of refining my own understanding.
Programming language is a tool of communication, a middleman, as our brains understand logics and ideas while the computer brains only understand zeros and ones. We translate "if Andy is greater than or equal to 21, then he can consume alcohol" into "0101001011010101010100101010101010101010".
Digital Electronic technology converts that code that the computer understands into a physical phenomenon that is voltages signalling "true" and "false" -- high and low voltages. That is: "0101001011010101010100101010101010101010" into "nozap-zap-nozap-zap-nozap-nozap-..."
That, or the other way around. Voltage -> binary system (true/false) -> computer "brains" -> programming language.
Posting Freak
Posts: 6,070
Threads: 229
Joined: 2008-07
I probably can't give you a satisfactory answer for your main question, but it basically amounts to electric signals, basic electric components and switches. For example, if I press a key on a keyboard, it completes a circuit and a signal is sent from the keyboard to the computer. (Actually it ignores it for a millisecond or so since the key bounces for a bit, because physics > ideal reality, but I'm distracting you right now.) The mix of these circuits and electric components let the computer do basic math, and from there on, more math, more math, and so forth until you have software programs. The CPU specializes in integer operations, while the GPU specializes in parallel floating point operations.
There are two reasons I can think of off the top of my head why computers use binary: it's an incredibly efficient means of representing and storing data without losing information (between reading and writing it; sometimes they're different processes and aren't reverses of each other), and it's also the simplest in basic recognition. For the latter, a high voltage value represents a "1", and a low voltage value represents a "0".
As for your side question, infinite loops destroy things by, at the very least, using the computer. Pretty much everything has wear and tear; even bridges are rated with 10^8 vehicle passes or something before they warrant inspection, err the bridge collapses. The same thing happens with metal: if you run a current through it, it causes oxidation and it ruins the conductivity of the metal. Now it may not seem that such a small current could do that, and you'd be wrong. Water "boils" and becomes vapor at room temperature, even though if it takes a very long time to do so. The key thing to remember is that it mostly happens on the microscopic scale. Running an infinite loop is basically the equivalent of you doing the same mathematical operations over and over again without delay.
That alone however is hardly the main reason why it would pineapple modern computers. Since computers don't wait to do their tasks (unless you specifically told it to), it will allocate a portion of the (infinitely large) task to other threads/processors. This eventually leads to the whole computer being dedicated to the infinite loop, and the computer may become unresponsive. If the infinite loop happens on a very basic scale, say assembly, memory leaks can happen, which consumes all available memory (not the same as processing power), and may cause other devices or critical programs to crash. Crashing your computer is not a good thing, as abnormal conditions arise where the hardware may not be designed to deal with safely and consistently.
Posting Freak
Posts: 2,715
Threads: 212
Joined: 2010-03
Gender: Male
1 = On
0 = Off
Electricity travels depending on the switches' current state. That's how electricity travels, but this is the dumbed-down version and any IT-major would gladly go into more details than I would.
Senior Member
Posts: 737
Threads: 34
Joined: 2010-08
This site might help http://computer.howstuffworks.com/microprocessor.htm As for infinite loops it would do the same harm as my Symantec product does on a daily basis; it keeps stuff running, wearing it out. It's not as quick a process as short circuiting an electric current because each of those switches serve as resistance and computers are supposed to handle near-infinite calculations. The process of manufacturing individual circuits and chips would be proprietary, but the general process is shown here http://www.madehow.com/Volume-2/Integrated-Circuit.html
Posting Freak
Posts: 854
Threads: 71
Joined: 2008-07
Gender: Male
Sexual Orientation: Straight
Country Flag: usa
Job: Software Dev.
First of all, CPUs do not understand languages like C or C++. They only understand the binary instruction set for that particular processor. Languages like C and C++ get turned into binary by a program called a compiler. A CPU has the ability to load and store values to and from memory as well as to and from locations inside the CPU called registers. Registers are faster than memory. A CPU has a special register called the instruction pointer. The instruction pointer is a number that refers to a location in memory. At the beginning of each clock cycle, the CPU does the following:
1. Load the instruction located at the memory location indicated by the instruction pointer.
2. Increment the instruction pointer so it refes to the next instruction.
3. Figure out what the instruction means and execute it. An instruction might be "Load the 4 bytes starting at memory location 1395739 and put them in register 6" or
"multiply the values in register 2 and register 6 and put the result in register 1" or even "change the value of the instruction pointer to 29832"
One way for the CPU to communicate with devices like a hard drive is to put certain values indicating commands or data in a special memory location and then send a signal to the device. The device can communicate with the CPU in a similar way, putting data in a special memory location and then triggering an interrupt, which makes the CPU stop its normal execution and start executing an interrupt handler. When the interrupt handler is done, the CPU goes back to what it was doing.
As others have said, an infinite loop does not destroy a processor other than the slow effect of normal wear and tear.
Posting Freak
Posts: 6,406
Threads: 399
Joined: 2008-07
Gender: Male
I have often wondered the same thing as the OP, at least how I am reading it, but I find these answers kind of vague. They touch on the general concepts of binary and on/off or 1/0.
How does a compiler translate "int i = 0; while (true) { i++; }" into an infinite process of summation? "A compiler does it" does not suffice for me.
A compiler is a program, and it compiles written code into a program. That creates a loop, so how did the first compiler exist? How do you go from basic binary circuity akin to Minecraft's Red dust to the complex systems used everyday by billions?
I suppose, ultimately, what I want to know is this: How could a person manually compile a program? I realise it would be incredibly complex for most programs and there is no reason to do it other than knowing for the sake of knowing.
On a mildly related subject, why will a binary that works on Windows not work on Linux and vise-versa? (I have no idea how Mac uses binaries.)
I might be diverting from the OP's train of thought, though.
Test Mushroom
Posts: 10,045
Threads: 1,506
Joined: 2008-06
Gender: Male
Sexual Orientation: Straight
Country Flag: usa
IGN: GuavaCowboy
Server: Zenith
Level: 10x
Job: Jett
Guild: L>
The answer is microcode. I asked the same question a few weeks ago here:
http://stackoverflow.com/questions/37060...on-the-cpu
Posting Freak
Posts: 854
Threads: 71
Joined: 2008-07
Gender: Male
Sexual Orientation: Straight
Country Flag: usa
Job: Software Dev.
Hazzy Wrote:I have often wondered the same thing as the OP, at least how I am reading it, but I find these answers kind of vague. They touch on the general concepts of binary and on/off or 1/0.
How does a compiler translate "int i = 0; while (true) { i++; }" into an infinite process of summation? "A compiler does it" does not suffice for me.
A compiler is a program, and it compiles written code into a program. That creates a loop, so how did the first compiler exist? How do you go from basic binary circuity akin to Minecraft's Red dust to the complex systems used everyday by billions?
I suppose, ultimately, what I want to know is this: How could a person manually compile a program? I realise it would be incredibly complex for most programs and there is no reason to do it other than knowing for the sake of knowing. Clearly, someone, at some point in history, had to write an assembler in binary. An assembler is a "compiler" for assembly language, which is basically a human-readable language that translates directly into binrary, unlike C or C++ where there's more than one way to translate the code into binrary. They would do it by looking at a manual of the instruction set for the CPU and seeing how to encode an ADD instruction into binary, a MOVE instruction, etc and manually putting together the bytes of binary code.
This doesn't need to be done for every new kind of processor or operating system. Once you have a compiler on one system, you could rewrite it in the higher level language and use the first compiler to compile the second compiler. Then you can use the second compiler to compile future versions of itself. This would make it easier to extend the compiler to compile to binary code for other processors and operating systems, called cross-compiling.
There is no compiler that runs on the Nintendo DS, for example. Developers write the code on their computers and use a cross-compiler.
Hazzy Wrote:On a mildly related subject, why will a binary that works on Windows not work on Linux and vise-versa? (I have no idea how Mac uses binaries.)
I might be diverting from the OP's train of thought, though.
You're right in that you're still on the same kind of CPU so the binary instruction set is the same. But there are two reasons why a windows binary will not work in Linux and vice-versa.
1. A Windows .exe file or a Linux executable file do not just contain CPU instructions. They can also contain metadata such as the program version and program author. They also contain initialized global data and the initial memory layout of the program. See the Wikipedia article on Object File for more. Windows uses the Portable Executable (PE) format while Linux uses the Executable and Linkable Format (ELF). There is a part of an operating system called a loader that takes that executable format and sets up the program in memory before handing the program to the CPU.
2. For a program to do anything useful, it will need to use some system calls, functions that are executed by the operating system. Programs (aside from operating systems and device drivers) are not given direct access to devices like the hard drive. Instead they must ask the operating system to open a file and write these 200 bytes. Windows and Linux have different functions for opening and writing to files.
Posting Freak
Posts: 3,213
Threads: 466
Joined: 2008-07
2147483647 Wrote:How is a program (C, C++, binary?) able to affect change the properties of a processor? In other words, how do words and letters typed into an interface cause (electricity?, magnetism?, wave signals?) to move within the tiny pieces of metal that make up a computer? The answer to that question takes me 5 years to find. Still 3.5 years left. (If you want a good elaboration as of why this works)
I'm afraid I may reach the character-limit of a post if I try to explain this well. I may as well ask what you know about CPUs and electricity:
Do you know how PMOS and NMOS work? NAND? Latches/Flip-flops? ALU? If not, I could probably try to swiftly learn you how.
2147483647 Wrote:Oh and as a side question, how does an infinite loop destroy the pieces of metal that make up the processor, or cause them to malfunction (in terms of physical processes) so that they are forever destroyed or unusable? More electrons through a wire cause the energy emitted higher and higher. The thing will in the end start melting, and funny thing happens.
Posting Freak
Posts: 6,406
Threads: 399
Joined: 2008-07
Gender: Male
Spaz Wrote:1. A Windows .exe file or a Linux executable file do not just contain CPU instructions. They can also contain metadata such as the program version and program author. They also contain initialized global data and the initial memory layout of the program. See the Wikipedia article on Object File for more. Windows uses the Portable Executable (PE) format while Linux uses the Executable and Linkable Format (ELF). There is a part of an operating system called a loader that takes that executable format and sets up the program in memory before handing the program to the CPU.
2. For a program to do anything useful, it will need to use some system calls, functions that are executed by the operating system. Programs (aside from operating systems and device drivers) are not given direct access to devices like the hard drive. Instead they must ask the operating system to open a file and write these 200 bytes. Windows and Linux have different functions for opening and writing to files.
If I were an Operating System developer, I would want my operating system to run programs more effectively than the current status-quo and I would want it to run existing software to make transitions easier. Why does Linux not use PE format when the file ends in .exe? Are there developmental limitations, legal restrictions, or something else altogether?
Or for that matter, why bother using ELF and different function names at all? Legal issues? I could go on and ask about Windows exclusive things like the .NET Framework, ActiveX, and DirectX, but the thread is starting to diverge.
Where does one learn this kind of stuff? "Computer Science in college" is probably the answer, but much too vague to be even remotely helpful.
Administrator
Posts: 17,191
Threads: 2,153
Joined: 2008-09
Gender: Male
Sexual Orientation: Gay
IGN: Aesilyn
Server: Mardia
Level: 200
Job: I/L ArchMage
Guild: Animus
Hazzy Wrote:If I were an Operating System developer, I would want my operating system to run programs more effectively than the current status-quo and I would want it to run existing software to make transitions easier. Why does Linux not use PE format when the file ends in .exe? Are there developmental limitations, legal restrictions, or something else altogether?
Or for that matter, why bother using ELF and different function names at all? Legal issues? I could go on and ask about Windows exclusive things like the .NET Framework, ActiveX, and DirectX, but the thread is starting to diverge. 
Where does one learn this kind of stuff? "Computer Science in college" is probably the answer, but much too vague to be even remotely helpful.
Read. Read. Read some more.
http://en.wikipedia.org/wiki/Executable_...ble_Format
http://en.wikipedia.org/wiki/Portable_executable
Posting Freak
Posts: 854
Threads: 71
Joined: 2008-07
Gender: Male
Sexual Orientation: Straight
Country Flag: usa
Job: Software Dev.
It's not merely the names of the functions that are different. The system interfaces were designed differently. Linux implements POSIX which means that programs designed for Linux are usually source-code compatible with the various flavors of Unix. POSIX is a fairly minimal interface but the Windows API has hundreds or thousands of functions. In Windows, the GUI is a part of the OS, while in Linux, the GUI (if present) is managed by a non-OS program.
There are many other differences in design. For example, in Linux and other Unix-like operating systems, a program that starts another program passes the command-line arguments as a list of strings. In Windows, the first program just passes one big string. If the second program wants to break it up, it can call CommandLineToArgvW (or if the program uses main as the entry point instead of WinMain, Windows will do that for you).
Linux binaries are not even compatible with binaries for other Unix-like operating systems like NetBSD. I'll be honest, I'm not entirely certain why that is. I suspect it has something to do with the operating systems having different ways of invoking a given system call.
Making an OS that is binary compatiblity with Windows is difficult, but ReactOS is trying. Linus Torvald's goal was not to be compatible with Windows; it was to create a free operating system. Linux could indeed run "existing software" designed for Unix-like operating systems after recompiling them. Bash and gcc were two of the first programs he got working on Linux.
Also remember that Linux started in 1991. Windows was still young (version 3.0) and not even an actual operating system yet - it was still just a graphical shell on top of MS-DOS.
.NET isn't exactly exclusive to Windows. Mono is a free implementation that can run on Linux.
I checked and apparently there is a kernel module for Linux that allows PE executables to be loaded.
A lot of the stuff in this thread is the kind of stuff that might be covered in a systems programming (sophomore-level) or operating systems (junior-level) course in college.
Administrator
Posts: 17,191
Threads: 2,153
Joined: 2008-09
Gender: Male
Sexual Orientation: Gay
IGN: Aesilyn
Server: Mardia
Level: 200
Job: I/L ArchMage
Guild: Animus
Spaz Wrote:A lot of the stuff in this thread is the kind of stuff that might be covered in a systems programming (sophomore-level) or operating systems (junior-level) course in college.
And to add to this it's far too in depth to be pissed off at people for only providing high level answers over.
If the general answers being given aren't enough for someone they need to go google stuff, because this is asking far too much that will devolve into far too many directions because there is no simple easy answer. This is several entire fields of study with conflicting approaches, different objectives, numerous implementations past present and planned and simply outside the scope of reasonable expectation.
Member
Posts: 194
Threads: 1
Joined: 2008-10
2147483647 Wrote:Say that there are pieces of metal and no computers exist. How would a processor be built, how would it be worked (manual switches?), and how would it give an output?
First computers -> vacuum tubes, from there you move to basic transistors and just keep getting smaller and smaller. Currently, Intel is down to 32nm transitors and is currently working on 22nm. As for output, vacuum tubes function almost exactly like transistors do. This is one reason why they were so easily replaced by them.
2147483647 Wrote:Oh and as a side question, how does an infinite loop destroy the pieces of metal that make up the processor, or cause them to malfunction (in terms of physical processes) so that they are forever destroyed or unusable?
First, an infinite loop doesn't destroy your CPU, anyone that's accidently made a coding error or torture tested their CPU/GPU can attest to that. Second, metal is not the biggest component of computer hardware. When hardware breaks down, it's generally the transistors (namely Metal-Oxide-Semiconductor Field-Effect Transistors - MOSFETs) which, outside the contacts, are not metal at all (Silicon and silicon dioxide being the most common pairing, though SiO2 is being replaced by high K dialectrics in new processors). Now, as for how they are destroyed, errrrrr, that's complicated. Basically, too much heat or voltage can cause the transistor to deteriorate over time. However, even under use, CPUs are made to last at least 10 years by which point most people buy new computers.
My apologies if this isn't conherent in any way, shape, or form...
Posting Freak
Posts: 6,070
Threads: 229
Joined: 2008-07
Eosian Wrote:Read. Read. Read some more.
This is basically how I cracked the data file encryption without help. Granted, I could have asked other people or downloaded a reader, but what's the fun in that?
About 98% of anything related to computers is pretty much guaranteed to be found on the internet, and you can guess why that is.
|