How does software interface with hardware ?

AFB

Lifer
Jan 10, 2004
10,718
3
0
I know there is assembly, and even binary, but how does the computer process this information ?
 

CTho9305

Elite Member
Jul 26, 2000
9,214
1
81
The assembly compiles to machine instructions (binary/hex/whatever... it's just a bunch of bytes), which the CPU interprets to mean things like "copy this location here" or "add these numbers".

edit: I guess that explanation isn't very good.

Consider a simple processor that has 4 instructions: copy, add, compare, and jump. The encodings are 00, 01, 10, and 11. The format of all instructions is: two bits for "opcode" (specifies the operation), 3 bits for the first operand, and 3 bits for the second (this computer supports a whopping 8 bytes of data memory). The jump instruction jumps to a different point in the program if the most recent compare showed operand1 was less than operand2, and can specify an address that is 6 bits long (since there is only one operand). Add does operand1 = operand1 + operand2

If the contents of the memory was:
[address in hex] [data in hex] data in binary - what it does
[000] [41] 01 000 001 - mem[0] = mem[0] + mem[1]
[001] [82] 10 000 010- status = mem[0] < mem[2]?
[002] [E8] 11 101 000 - if (status) jump to 005
[003] [39] 00 111 001 - mem[7] = mem[1]

[005] [38] 00 111 000 - mem[7] = mem[0]

If, instead of a single copy, you had a loop, code like that could be used in a game - add the number of points to the old score, and if it was less than some threshold, display a "Ha ha!" message on the screen ;).

If you're asking how that's actually implemented.... I have some book recommendations ;).
 

CTho9305

Elite Member
Jul 26, 2000
9,214
1
81
This might be useful to anyone else who sees the thread and wonders what happened:

a: So,how does the CPU interpret assembly ?
CTho9305: It doesn't. The assembly is compiled to machine instructions
a: I get that, how does it know what to do ?
CTho9305: well, it reads a few bytes from memory and looks at them
CTho9305: and then based on the pattern it sees, does various operations
a: So it already knows what to do based on preset codes. (ie assembly)?
CTho9305: right, there is a set of instructions, and every line of assmebly translates into one of those instructions
a: Ok, thank you.:D
 

AFB

Lifer
Jan 10, 2004
10,718
3
0
Originally posted by: CTho9305
This might be useful to anyone else who sees the thread and wonders what happened:

a: So,how does the CPU interpret assembly ?
CTho9305: It doesn't. The assembly is compiled to machine instructions
a: I get that, how does it know what to do ?
CTho9305: well, it reads a few bytes from memory and looks at them
CTho9305: and then based on the pattern it sees, does various operations
a: So it already knows what to do based on preset codes. (ie assembly)?
CTho9305: right, there is a set of instructions, and every line of assmebly translates into one of those instructions
a: Ok, thank you.:D

Thank you very much. :beer::)
 

rallyrulz

Member
Nov 26, 2003
25
0
0
Thats why with every new release of cpu, theres new instructions to go with it, whether it be SSE2, 3, MMX whatever, there is new assembly level instructions, the orignal ones would have just had the mov, add, div, sub, jmp and so on, these days they probably have tons, you can download and read about them actually, probably from intel technical specs section. TASM is an assembly compiler, and i think vs.net has v6.0 Where as borland 5 way back had 3 i think. So presumably these new tasm compiler executables will have the new cpu instructions loaded into them and compile code that is compatable between amd and intel. Right down at the hardware level, you have registers (ax, bx, cx, dx) are the primary ones, you have arithmetic logic units, they do the integer math, you have floating point units, they do the big long crunhy decimal numbers, and you have the execution unit which executes the actual instuctions (outsources the math, its like the business in the middle). And on a scale below that, you have logic gates, ands / ors/ nots /xors which when combined make 'adder' circuits for math, and the rest is some truely complex combinations which give it a brain. Combinations of transistors, resistors create all the gates.
 

CTho9305

Elite Member
Jul 26, 2000
9,214
1
81
Originally posted by: rallyrulz
Thats why with every new release of cpu, theres new instructions to go with it, whether it be SSE2, 3, MMX whatever, there is new assembly level instructions
I don't believe the 486 added any instructions. There's no fundamental reason to add instructions for new CPUs - for all we know, SSE3 could have been implemented only so Intel could say "Hey look, AMD processors don't support these 13 new instructions, and are therefore inferior, even though no software uses them!". Of course, other instructions (like the i586 CMOV) are probably very useful (it lets you conditionally set values without a branch instruction, so I would guess there is a MUCH lower performance penalty)

, the orignal ones would have just had the mov, add, div, sub, jmp and so on, these days they probably have tons, you can download and read about them actually, probably from intel technical specs section.
The "original" instruction set was still somewhat large, depending on what you call original (808x?)

TASM is an assembly compiler, and i think vs.net has v6.0 Where as borland 5 way back had 3 i think.
NASM, MASM, a86, gas, there are lots of assemblers for x86. I don't think the second part of your not-sentence means anything ("vs.net has v6.0"? comes with TASM 6.0?)

So presumably these new tasm compiler executables will have the new cpu instructions loaded into them and compile code that is compatable between amd and intel.
Any old compiler can compile code that will be compatible - seeing as both of the companies make processors implementing the same instruction set.

Right down at the hardware level, you have registers (ax, bx, cx, dx) are the primary ones, you have arithmetic logic units, they do the integer math, you have floating point units, they do the big long crunhy decimal numbers, and you have the execution unit which executes the actual instuctions (outsources the math, its like the business in the middle). And on a scale below that, you have logic gates, ands / ors/ nots /xors which when combined make 'adder' circuits for math, and the rest is some truely complex combinations which give it a brain. Combinations of transistors, resistors create all the gates.
I don't think that explains how it's actually implemented very well.
 

Sahakiel

Golden Member
Oct 19, 2001
1,746
0
86
Right down at the hardware level, you have registers (ax, bx, cx, dx) are the primary ones, you have arithmetic logic units, they do the integer math, you have floating point units, they do the big long crunhy decimal numbers, and you have the execution unit which executes the actual instuctions (outsources the math, its like the business in the middle). And on a scale below that, you have logic gates, ands / ors/ nots /xors which when combined make 'adder' circuits for math, and the rest is some truely complex combinations which give it a brain. Combinations of transistors, resistors create all the gates.
I don't think that explains how it's actually implemented very well.

Registers are memory units which store data. The data can be sources or destinations for operations.
ALU operate on numbers. They can be very simple single operation units or complex multi-purpose units. Traditionally integer only.
Floating point units are ALUs for fractions. Most popular uses IEEE standard formats.
Execution units are, well, where the execution takes place. Types include addition, integer, multiplication, floating point, branch, load, store, etc.
Logic gates are the basic building blocks of everything. ANDs, ORs, NANDs, NORs, XORs, XNORs, you can build everything out of NANDs if you wanted.
All gates are made of transistors. Resistors can be constructed using transistors and are alongside gates. In fact, every basic circuit component can be made using transistors. Except maybe inductors; I'm at a loss as to how to make one.
 

Peter

Elite Member
Oct 15, 1999
9,640
1
0
You got your thinking process all backward there.

Machine code is the ONLY thing the CPU understands and interprets. Eventually, EVERY single piece of software is presented to the CPU in machine language format, be that a 3D rendering package or the hardware driver that sends data out the printer port.
Things written in higher languages need to be compiled first - this is the process that makes machine code from programming language.

The machine code instruction set of a certain CPU is of course cast in iron by this very CPU's design. That's how it knows what to do.
 

gsellis

Diamond Member
Dec 4, 2003
6,061
0
0
I do think the 486 did add instructions. I remember using an optimization for it during compile in OS/2.

Also, and it has been a long time so don't beat me up if I remember incorrectly, the whole RISC / CISC thing came from the worry that the decoder that converted the assembler to machine language would become a bottleneck. Therefore to simplify it, they developed the RISC arch. Technology came along and made it mostly mute.
 

Delorian

Senior member
Mar 10, 2004
590
0
0
In 2000 and I believe XP as well the OS loads what's called a HAL or Hardware Abstraction Layer. This is the interface for hardware requests from different software while in the OS. The HAL acts as an intermediary to give programs what they need to run and not have conflicts between requests. Though not very compatible with some older programs. You can read more about this in Microsofts labyrinth of a database on their website. Hope this helps.



What are you doing dave?

That is highly irregular!
 

CTho9305

Elite Member
Jul 26, 2000
9,214
1
81
Originally posted by: gsellis
Therefore to simplify it, they developed the RISC arch. Technology came along and made it mostly MOOT.

Hardly... with a modern x86 processor you have something like 2 fetch and 2-3 decode stages. Every extra pipe stage is an extra performance hit when you have a branch misprediction and is a waste of power. One major thing is that instruction sets with fixed instruction lengths make the fetch unit significantly simpler (of course, a tradeoff is that you probably end up with longer average instruction lengths and therefore more memory bandwidth and cache size needed).

I think that even though modern x86 processors do a good job, a LOT of extra effort is required due to the complexities of x86.
 

zephyrprime

Diamond Member
Feb 18, 2001
7,512
2
81
I don't believe the 486 added any instructions. There's no fundamental reason to add instructions for new CPUs
The 486 did add new instructions. I don't really remember what they are though. They weren't that exciting.

But the thing is, you need to understand how circuitry works in order to answer your question. It's actually pretty simple once you know that. I can't explain it to you because it really requires drawing stuff which I can't do an AT. After you see how simple circuitry works, you can take a look at some old time simple processor designs and then you will have the answer to your question. You'll probably need some college textbooks to do this because searching on the web for this sort of stuff can be a pain.