How does code gets converted/executed on a computer?

  • (2 Pages)
  • +
  • 1
  • 2

22 Replies - 4511 Views - Last Post: 18 April 2012 - 04:04 AM

#1 kaylled   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 22-April 09

How does code gets converted/executed on a computer?

Posted 18 December 2011 - 02:25 PM

Hello everyone

I have searched a lot but can't find any answers to my question:

When does software and "metal" meet on a computer? what I have in mind is how does text/code get converted into
electrical signals and gets executed?

any links and stuff could be very helpful...

thanks in advance
Is This A Good Question/Topic? 0
  • +

Replies To: How does code gets converted/executed on a computer?

#2 Oler1s   User is offline

  • D.I.C Lover
  • member icon

Reputation: 1397
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: How does code gets converted/executed on a computer?

Posted 18 December 2011 - 04:54 PM

Research the terms compiler and machine code.
Was This Post Helpful? 0
  • +
  • -

#3 DimitriV   User is offline

  • vexing conundrum
  • member icon

Reputation: 587
  • View blog
  • Posts: 2,746
  • Joined: 24-July 11

Re: How does code gets converted/executed on a computer?

Posted 18 December 2011 - 04:56 PM

Hi
On a Mac the software relies on a 'Kernel' which is a piece of software that relays messages and bridges the gap between the hardware and software.
http://www.google.co...OGaOWiQfytaG8BQ
Was This Post Helpful? 0
  • +
  • -

#4 GunnerInc   User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 931
  • View blog
  • Posts: 2,376
  • Joined: 28-March 11

Re: How does code gets converted/executed on a computer?

Posted 18 December 2011 - 05:07 PM

Search term: "how does a cpu execute programs"
Results: TONS!

compile a program and open it in a hex editor, see all those nubmers? Most of those are opcodes - instructions the CPU understands.

In a nutshell, the OS loader loads your program into memory (does a few calculations) and sets the EIP register to the address of the first instruction, the cpu executes that instruction and increments the address in EIP according to the opcode size, executes the next instruction.. this keeps going in a linear fashion from A to Z. Skipping some code according to compares and jmps. When you call a function, the cpu skips to the address of that function but returns to the spot right after the call.. Nutshell, it is very in depth as to the workings of the CPU
Was This Post Helpful? 3
  • +
  • -

#5 DimitriV   User is offline

  • vexing conundrum
  • member icon

Reputation: 587
  • View blog
  • Posts: 2,746
  • Joined: 24-July 11

Re: How does code gets converted/executed on a computer?

Posted 18 December 2011 - 05:08 PM

And that, my friends, is why GunnerInc is an expert.
Was This Post Helpful? 1
  • +
  • -

#6 GunnerInc   User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 931
  • View blog
  • Posts: 2,376
  • Joined: 28-March 11

Re: How does code gets converted/executed on a computer?

Posted 18 December 2011 - 05:12 PM

Smartass :tt2:
Was This Post Helpful? 0
  • +
  • -

#7 DimitriV   User is offline

  • vexing conundrum
  • member icon

Reputation: 587
  • View blog
  • Posts: 2,746
  • Joined: 24-July 11

Re: How does code gets converted/executed on a computer?

Posted 18 December 2011 - 05:13 PM

I meant it, dead set legit.
Was This Post Helpful? 0
  • +
  • -

#8 kaylled   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 22-April 09

Re: How does code gets converted/executed on a computer?

Posted 18 December 2011 - 05:29 PM

View PostGunnerInc, on 18 December 2011 - 05:07 PM, said:

Search term: "how does a cpu execute programs"
Results: TONS!

compile a program and open it in a hex editor, see all those nubmers? Most of those are opcodes - instructions the CPU understands.

In a nutshell, the OS loader loads your program into memory (does a few calculations) and sets the EIP register to the address of the first instruction, the cpu executes that instruction and increments the address in EIP according to the opcode size, executes the next instruction.. this keeps going in a linear fashion from A to Z. Skipping some code according to compares and jmps. When you call a function, the cpu skips to the address of that function but returns to the spot right after the call.. Nutshell, it is very in depth as to the workings of the CPU


ya, but when in this process does "dead metal/silicon" becomes able to "read & understand" the instructions in the registers? or put in other terms: how does software which is "text" gets converted to electrical signals on/off?
Was This Post Helpful? 0
  • +
  • -

#9 DimitriV   User is offline

  • vexing conundrum
  • member icon

Reputation: 587
  • View blog
  • Posts: 2,746
  • Joined: 24-July 11

Re: How does code gets converted/executed on a computer?

Posted 18 December 2011 - 05:31 PM

Processed, converted to true or false, or 0 or 1, or yes or no, or however you wish to call it.
Was This Post Helpful? 0
  • +
  • -

#10 GunnerInc   User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 931
  • View blog
  • Posts: 2,376
  • Joined: 28-March 11

Re: How does code gets converted/executed on a computer?

Posted 18 December 2011 - 05:39 PM

No, your program is NOT text. It gets compiled to opcodes that the CPU understands. There are TONS of papers on the internals of a CPU from the one in your remote control, your car radio to your computer. Visit the Intel and AMD site for documents.

When the CPU gets made, it is built with microcode that understands the opcodes which opens/closes certain circuits. CPUS contain an ALU and CU, the CU decodes the opcodes, the ALU does math and logic. Read on the net, way too much info to explain here.
Was This Post Helpful? 1
  • +
  • -

#11 kaylled   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 22-April 09

Re: How does code gets converted/executed on a computer?

Posted 18 December 2011 - 05:50 PM

View PostGunnerInc, on 18 December 2011 - 05:39 PM, said:

No, your program is NOT text. It gets compiled to opcodes that the CPU understands. There are TONS of papers on the internals of a CPU from the one in your remote control, your car radio to your computer. Visit the Intel and AMD site for documents.

When the CPU gets made, it is built with microcode that understands the opcodes which opens/closes certain circuits. CPUS contain an ALU and CU, the CU decodes the opcodes, the ALU does math and logic. Read on the net, way too much info to explain here.


thanks that was helpful, but can you link me to some stuff that explains when the opcodes and the metal bridges?
Was This Post Helpful? 0
  • +
  • -

#12 GunnerInc   User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 931
  • View blog
  • Posts: 2,376
  • Joined: 28-March 11

Re: How does code gets converted/executed on a computer?

Posted 18 December 2011 - 06:13 PM

Search for CPU design and be prepared to read A LOT.

Info for AMD and INTEL, I am missing a few books (I think they are under my bed) so can't tell you which ones you want, they are all relevant though

http://www.intel.com...rds=&topicarea=

http://developer.amd...es/default.aspx
Was This Post Helpful? 0
  • +
  • -

#13 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6968
  • View blog
  • Posts: 31,958
  • Joined: 10-May 07

Re: How does code gets converted/executed on a computer?

Posted 18 December 2011 - 06:24 PM

View Postkaylled, on 18 December 2011 - 07:29 PM, said:

ya, but when in this process does "dead metal/silicon" becomes able to "read & understand" the instructions in the registers? or put in other terms: how does software which is "text" gets converted to electrical signals on/off?

It's all a matter of addressing. The CPU addresses memory, the memory stores instructions & values. All execution must occur in memory. Data is pulled from the hard drive, loaded into memory, executed.

When the computer is 1st turned on, all hard ware is addressed & mapped. Other than what has previously been provided by Gunner, this information is very detailed & available on the internet. It's no secret of hardware communicates, & loads software for execution.
Was This Post Helpful? 0
  • +
  • -

#14 blackcompe   User is offline

  • D.I.C Lover
  • member icon

Reputation: 1159
  • View blog
  • Posts: 2,547
  • Joined: 05-May 05

Re: How does code gets converted/executed on a computer?

Posted 18 December 2011 - 06:48 PM

*
POPULAR

Understand that keyboard strokes enter memory buffers as bits. Suppose I have a 5-bit bus from my keyboard to internal bus, which puts those bits into an internal memory buffer. A 5-bit bus is simply 5 wires that propagate electrical signals. 2^5 allows me to have 32 mappings. Suppose I have this keyboard mapping:

a = 0
b = 1
c = 2
d = 3
.
.
z = 25

I press 'z' on my keyboard, which is 25 or 11001. An encoder places a signal on lines 1, 2, and 5. Now the memory buffer contains 11001.

                   Selected
                      |
Kybd |A| |B| |C| ....|Z|
       \  |   |     /
       ------------
       |  Decoder |
       ------------
         | | | | |
Bus      | | | | |
         | | | | |
       -------------
Memory | 1|1|0|0|1 |
       -------------



Pretty straight forward. How is this signal (electrical energy or the flow of electrons) stored in the hardware?

Realize the ways that a bit of information can be stored in hardware. One way is to store it in a capacitor: a device that stores energy. DRAM uses capacitance-based memory (with transistors), which has to be refreshed since the charge leaks. If there's no charge in it, it's a 0, otherwise a 1. CPU components use flip-flops.

From there the CPU has access to memory. It bring its contents into registers and operates on it, as directed by the program it's running. The CPU is designed to operate according to the opcodes that it receives. Often you hear of Intel-based PC's referred to as the x86 platform, which is also the name of Intel's assembly language.

It's not the program that determines what's text and what's instructions; it's the programmer. It's possible to design hardware that implements algorithms, but it's costly and more complex.

All hardware components are designed to operate in a specific way.

Quote

thanks that was helpful, but can you link me to some stuff that explains when the opcodes and the metal bridges?


Book recommendations:

Computer Organization and Design: A high-level treatment of hardware, but enough to get the picture and infer how things are done.

Electronic Circuits: You have to do your research, many of these books require Integral Calculus. Something like Schaum's Outline of whatever may be more appropriate.

Some key terms: data path, ALU, multiplexer, encoder/decoder, barrel shifter, control logic, read/write register file, program counter, transistor, resistor, transducer, operational amplifier (analog to digital conversion), cache, translation look-aside buffer, bus, and interrupt controller.

I'm a fan of the bottom-up learning approach, which requires diving into circuit analysis first, but top-down is best if you don't want to subject yourself to dry reading material.

There really needs to be a Wiki for this stuff.

This post has been edited by blackcompe: 29 December 2011 - 10:24 AM

Was This Post Helpful? 5
  • +
  • -

#15 kaylled   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 22-April 09

Re: How does code gets converted/executed on a computer?

Posted 19 December 2011 - 01:56 AM

@blackcompe, wow great answer
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2