how do hardware and software really interface?

zillafurby

Banned
Mar 16, 2004
219
0
0
please explain how a piece of hardwired circuit can interface with software, i dont understand it, other than the software gets compiled to machine code and the hardware 'understands' it, how does hardware understand machine code, and how does it turn software code into machine code?

thanks.
 

CTho9305

Elite Member
Jul 26, 2000
9,214
1
81
Did you read this thread? If so, what don't you understand?

One key thing to remember is that hardware doesn't "understand" anything. It's just a bunch of hard-wired logic gates that can do things like evaluate "are a AND b both true?", "is a OR b true?".
 

movinslow

Senior member
Jul 15, 2002
246
0
0
Originally posted by: CTho9305
One key thing to remember is that hardware doesn't "understand" anything. It's just a bunch of hard-wired logic gates that can do things like evaluate "are a AND b both true?", "is a OR b true?".

hmm, ok, so how do logic gates work? How do they evaluate?
 

Sahakiel

Golden Member
Oct 19, 2001
1,746
0
86
Originally posted by: movinslow
Originally posted by: CTho9305
One key thing to remember is that hardware doesn't "understand" anything. It's just a bunch of hard-wired logic gates that can do things like evaluate "are a AND b both true?", "is a OR b true?".

hmm, ok, so how do logic gates work? How do they evaluate?

Transistors.

If you don't know how they work, picture a simple voltage source tied to a resistor and ground. Add a switch before or after the resistor. Add a voltmeter. Mix and match to your heart's content and you've got logic gates.
 

blahblah99

Platinum Member
Oct 10, 2000
2,689
0
0
If you're asking about the physical interface, then its nothing more than a bunch of binary code.


For example, when you're writing visual basic code to send data out the parallel port and write out two bytes of data, "A0" in this case. In binary, that means "10100000". If you get a multimeter and probe the data pins of the parallel port, you'll see 5V on d7, 0V on d6, 5V on d5, and 0V on d4-d0. That voltage can then be used to drive leds, switches, relays, etc etc.


How does a "1" translate into 5V? Well, that's the whole concept of digital logic and circuits. If you took a 9V battery and made a wired morse code rig, you could tap the 9V battery and your friend on the other end could see when there's 9V and 0V, or 1's and 0's. If you two define a string of "0000" as A, and "0001" as B, etc etc, you have a form of communication and can communicate just by morse code.
 

warhorse

Member
Dec 1, 2001
28
0
0
Let me try it from the perspective of a computer scientist with no knowledge of EE. A lot of commands have their own wire on the bus. Let's consider SCSI. There is a wire dedicated to saying "I want to talk on the bus" There are 8 wires then, 1 for each device so that a device can say "I am device x and I want to talk to device y" (the wire also signifys priority so the highest wire gets to go first). As long as all of the devices understand that, then it works. From the software side everything has an address. All you do is set that address to some value, and the computer will raise or lower the voltage to that address appropriately (I think that's right). Then, any device listening to that wire can check and say, "oh, the voltage on this wire is above some threshold, so I'll take that to mean the bit value is 0" or "the voltage on this is zero or at least below some threshold, I'll take it to mean 1."

Correct me if I'm wrong, I have taken zero EE classes
 

Matthias99

Diamond Member
Oct 7, 2003
8,808
0
0
At the CPU level, yes (see the thread referred to above). There really aren't *that* many instructions, though, and a lot of them are fairly esoteric 'extensions' to the basic x86 instruction set (like MMX, 3DNow, SSE1/2/3).
 

sao123

Lifer
May 27, 2002
12,656
207
106
Well sort of...but thats not acutally how it works...Lemme try to explain this in simpleness....

Here is a fictional CPU which has 2 functions...and & or. It has 3 input lines and 1 output line. (i hope you understand & or)
and -> 0 & 0 = 0, 0 & 1 = 0, 1 & 0 = 0, 1 & 1 = 1
or -> 0 | 0 = 0, 0 | 1 = 1, 1 | 0 = 1, 1 | 1 = 1

Of the 3 input lines, 1 (C) is a control line (instruction) and 2 (A & B) are data inputs. The output line (Z) is also data output.
There are 9 possible instructions 000,001,010,011,100,101,110,111 with the instructions being ion the format CAB
With C = 0 being perform "or" and c = 1 being perform "and" of A & B.

A -\
B - AND-\
C--------- AND-\
........................OR - Z
C--------- AND-/
B - OR-/
A -/

C = "not C" is the opposite of C (in digital circuitry)

Hopefully you can see that both operations are performed on A and B but the correct output is selected using the control value C.

If C = 0 and C = 1 so that the "OR" (bottom half) answer is the one that comes out, because the "or" answer would be anded to 1 and the "and" answer would be anded to 0...

if C = 1 and C = 0, so that the "and" (top half) answer comes is the one that comes out, because the "or" answer would be anded to 0 and the "and" answer would be anded to 1...

The idea is that you and the answer you dont want with zero (making it zero) and then only the other answer will come out.



Real CPU's work similarly (although this is way overly simplified)
hopefully balhblah99s answer will help you understand the voltages associated with digital logic.

so in short the data input voltages go throughout the entire cpu, but its the contol lines that determine what comes out. Now what you must understand is there is a separate unique circuit for every operation (or instruction) a cpu can perform. So the answer to your question is yes, every instruction is hard coded into the cpu and they all activate at the same time, but the combination of the control lines physically selects what is the correct output.

 

CTho9305

Elite Member
Jul 26, 2000
9,214
1
81
Originally posted by: zillafurby
so what is a floating point operation?

An operation on a number like "1.5" instead of just "1" or "2". It's still implemented using the same type of logic gates - they're just wired together differently.
 

sao123

Lifer
May 27, 2002
12,656
207
106
Wow isnt that a loaded question...I hope you have some basic knowledge of how a computer works...This question could be an entire semesters worth of learning (I taught it, I should know)

First when a program is written, then it must be compiled and linked. The act of compiling a program translated the human written language into binary. The linking is then responsibe for setting up the memory. programs have two primary types of data (staic & dynamic). Every program once linked it a complete entity, inside a closed shell called its enviroment or scope. The most outer scope of a program has 2 distinct regions data & the program code itself. Withing the data region is a program stack (not to be confused with the system (or OS) stack). The bottom of the stack is called the base and the base pointer points to it. The top of the stack is where new items are inserted into the stack, and the stack pointer points to it. Variables are the most common form of static data, during the linking, these variables are places on the stack first (meaning they are on the bottom and the stack grows upward.)
Then as the program runs and calls functions etc...more items are added to the stack and removed as needed. To access your variables the linker translates the address as BP + [x] where X is some number identifying the position of your variable. In short all variables are stored in one great big array and are translated to physical addresses as BP[x] by the linker.
The other type of data is dynamic. This is a bit more involved, but as dynamic space is allocated and deallocated, it comes from and is returned to the heap. The heap is controlled by the operating system. If space is allocated but not deallocated when the program has terminated or finished, it is lost until the computer reboots. This is known as memory leak. Much like the stack heap space is addressed by HP[x] with some offset X, controlled by the OS, not by the linker in this case.

Now the program code region is always placed in the shell and when a program is loaded by the OS, the address of first instruction (also set by the linker) is given to the CPU as a starting point. Program execution continues step by step in order until a brach is reached. A branch is a place where a decision must be made and then a path followed. A prime example is... IF x = 3 GOTO Z... if x was 3 the program nxt execution step starts at label Z. if x did not equal 3, then execution continued at the next step proceeding this statement. This is known as flow of control. This process continues until the CPU reaches the instruction telling the CPU end of program. The program stopsn and control resumes by the OS.

Hope my answer in a nutshell was helpful...but ask more questions as necessary.