How does code gets converted/executed on a computer?

  • (2 Pages)
  • +
  • 1
  • 2

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

#16 iniaes  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 34
  • View blog
  • Posts: 142
  • Joined: 23-October 10

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

Posted 20 December 2011 - 05:01 AM

I highly reccomend that you read Code, by Charles Petzold, it takes you step-by-step through everything you have asked about, in gloriously deep detail, from how we have abstracted information with various kinds of code, all the way through to how a Assembly language program controls the CPU.

http://www.amazon.co...24382298&sr=8-3
Was This Post Helpful? 2
  • +
  • -

#17 kaylled  Icon 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 20 December 2011 - 02:45 PM

@iniaes, thanks for your recommendation, I will certainly read it...
Was This Post Helpful? 0
  • +
  • -

#18 calvinthedestroyer  Icon User is offline

  • D.I.C Lover

Reputation: 167
  • View blog
  • Posts: 1,908
  • Joined: 13-October 07

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

Posted 21 December 2011 - 09:40 AM

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

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?

You should look into TTL (Transistor - Transistor Logic)
http://en.wikipedia....ransistor_logic

Simply put, a computer Bit is represented by ether 5V = a binary one, or 0V = a binary zero (some newer systems use a lower voltages than 5V)

I would recommend starting with trying to under stand a simple 8bit CPU like the 8086. That will give you a basic understanding of how Physical Voltages translate into computer software.

8086 (x86, instruction set)
Was This Post Helpful? 1
  • +
  • -

#19 111027  Icon User is offline

  • D.I.C Head

Reputation: 17
  • View blog
  • Posts: 141
  • Joined: 26-December 11

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

Posted 26 December 2011 - 07:35 AM

View Postblackcompe, on 18 December 2011 - 06:48 PM, said:

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. I doubt you'd ever see this done. If there's no charge in it, it's a 0, otherwise a 1. Modern (and past) memory uses flip-flops, which are circuits that need to be refreshed every clock cycle.

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.



Interested in writing the Wiki? You seem to know enough about the subject.
Was This Post Helpful? 0
  • +
  • -

#20 calvinthedestroyer  Icon User is offline

  • D.I.C Lover

Reputation: 167
  • View blog
  • Posts: 1,908
  • Joined: 13-October 07

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

Posted 28 December 2011 - 06:23 PM

View Post111027, on 26 December 2011 - 07:35 AM, said:

View Postblackcompe, on 18 December 2011 - 06:48 PM, said:

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. I doubt you'd ever see this done. If there's no charge in it, it's a 0, otherwise a 1. Modern (and past) memory uses flip-flops, which are circuits that need to be refreshed every clock cycle.

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.



Interested in writing the Wiki? You seem to know enough about the subject.


5 bits? Wouldn't that be EBCDIC encoding?
Was This Post Helpful? 0
  • +
  • -

#21 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1150
  • View blog
  • Posts: 2,528
  • Joined: 05-May 05

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

Posted 28 December 2011 - 06:56 PM

Quote

Interested in writing the Wiki? You seem to know enough about the subject.


There's too much to cover.

Quote

5 bits? Wouldn't that be EBCDIC encoding?


It's an example.

This post has been edited by blackcompe: 28 December 2011 - 06:57 PM

Was This Post Helpful? 0
  • +
  • -

#22 anonymouscodder  Icon User is offline

  • member icon

Reputation: 126
  • View blog
  • Posts: 710
  • Joined: 01-January 10

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

Posted 28 December 2011 - 07:46 PM

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

or put in other terms: how does software which is "text" gets converted to electrical signals on/off?

The 'on/off', that is the true/false values (or zeros and ones if you prefer) are voltage levels.

Looking in the link above you can see that for TTL chips any voltage between 0V to 0.8V represents the logical value false and any voltage higher then 2V represents the logical true. Anything in the range 0.8V to 2V represents undefined behavior.

You can read more here.
Was This Post Helpful? 0
  • +
  • -

#23 turboscrew  Icon User is offline

  • D.I.C Addict

Reputation: 100
  • View blog
  • Posts: 615
  • Joined: 03-April 12

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

Posted 18 April 2012 - 04:04 AM

This is also a good book, and here is some info too.

All in all, microprogrammed devices make it more visible how a processor works. Microprogram is a nice bridge between program code and digital electronics. Most of the bits in the code are digital signals driving some counter or latch or something.

Even more evident connection of instruction to digital electronics is seen in nanoprogrammed processors. There was one classic main-frame processor, that was nanoprogrammed, but I can't remember the name of the machine.

[EDIT]

Aah, found thisabout simple microcoded processor.

This might be simpler as a starting point.

This post has been edited by turboscrew: 18 April 2012 - 04:17 AM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2