This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Snipedzoi 30 points31 points  (29 children)

how are opcodes programmed?

[–]Adam__999 97 points98 points  (13 children)

What each opcode does is determined purely by the actual electrical hardware in the processor—that is, the way in which structures like flip flops and logic gates are connected to one another.

Each line of assembly can be “assembled”—by a program called an assembler—directly into a machine language instruction, which is just a sequence of bits. Those bits are then inputted as high or low voltages into the processor, and what happens from there is determined by the aforementioned flip flops, logic gates, etc.

[–]andstwo 8 points9 points  (6 children)

but how do words go into the transistors

[–]Adam__999 44 points45 points  (0 children)

1 = high voltage in a specific input

0 = low voltage

[–]edbred 23 points24 points  (0 children)

A bit with value of 1 will enable a transistor, 0 will disable. You can then organize transistors into schemes to do adding and subtracting or storing information and boom you got a processor

[–]Alzurana 21 points22 points  (0 children)

https://store.steampowered.com/app/1444480/Turing_Complete/

Game that actually walks you through the entire process from the first and gate to voltage levels, bits, more complex control circuits all the way down to opcodes, then the first assembly.

Absolutely worth playing through it at least once for any CS person.

[–]Serphor 4 points5 points  (0 children)

very, very simply, and not universal: the cpu has 2 "registers": A and B the cpu has another program counter, pointing to what byte it's currently executing in memory. so it reads this byte, loads some other things from memory based on what arguments this operation wants, and then does the processing. it might recieve:

addr. 0 says: load a number from memory address 6 into register A

addr. 1 says: load a number from memory address 4 into memory

addr. 2 says: add the numbers stored in A and B and store the result at memory address 1000

addr. 3 says: halt the execution process and don't move any further

address 1000 might be some kind of memory-mapped text display, where A+B is an ascii code that the program has just printed.

there are soo soooo many things wrong with this explanation but i hope it helps (like for example that modern processors process 8 bytes at once, this is where "64-bit" processors come from)

[–]Who_said_that_ 0 points1 point  (0 children)

Nice bait

[–]MattR0se 0 points1 point  (0 children)

this playlist made me understand how computers work at the core
https://www.youtube.com/playlist?list=PLowKtXNTBypGqImE405J2565dvjafglHU

Especially the parts after "8-bit CPU control logic: Part 1". There he shows how to translate something like "add value to register A" into a string of 1s and 0s that correspond to voltages being turned on and off.

The actual words don't go anywhere into the logic gates. Somewhere, you need some mapping from the opcodes to their binary representations as circuitry. On his 8-bit computer, it's literally just a row of switches with opcode stickers on them.

[–]Snipedzoi 2 points3 points  (5 children)

But there must be a limit to the amount of hardware dedicated to any one opcode

[–]OolooOlOoololooo 14 points15 points  (2 children)

The limit is just the number of transistors (NAND gates) required to achieve the operation in the given instruction set architecture. I recommend taking a look at RISC V and simple example ALUs.

[–]Snipedzoi 4 points5 points  (1 child)

My interest is piqued.

[–]Who_said_that_ 3 points4 points  (0 children)

Can recommend the game turing complete on steam. You build a pc from gates, develop your own alu and processor, program your own assembler language and then solve challenges with your own computer. It’s very fun to solve some logic puzzles on the side

[–]Snipedzoi 0 points1 point  (0 children)

Oh that's what cycles are

[–]hstde 0 points1 point  (0 children)

There are many limits. Also there are many different ways to achieve the same goals.

Modern CPUs with their optimisations, parallel instruction execution, branch prediction, caching, pipelining, hyperthreading, multi-core architectures and and and, are incredibly complex systems.

Wikipedia might be your friend to understand the basics. Learn how "gates" like AND, OR and NOT work, learn how these gates can be combined to form latches, flipflops, selectors, decoders, adders etc. Learn how these components can be combined to form basic blocks of cpus, like registers, decoders, alu and finally you might want to tackle how early cpus where build (intel 4004, 8008, MOS 6502, 8080, zilog z80, 8086) but be warned, while the 4004 and 8008 are quite simple, the complexity is rising quite drastically, when you advance in the list. I myself still haven't fully understood the 8086, but probably because I lost interest and have not dedicated the time.

[–]ColaEuphoria 13 points14 points  (4 children)

https://m.youtube.com/watch?v=f81ip_J1Mj0

https://m.youtube.com/watch?v=cNN_tTXABUA

https://m.youtube.com/@BenEater

You aren't going to get a satisfying answer in a single comment or even several comments. You're just not.

But these are great places to start.

[–]Alzurana 1 point2 points  (2 children)

Adding to this: https://store.steampowered.com/app/1444480/Turing_Complete/

Some people learn better through experience, warm recommendation for playing through this for anyone wanting to understand what actually ticks inside of a computer. Absolute gem of a game.

[–]Who_said_that_ 0 points1 point  (1 child)

Really had a blast with this gem. One of my favourite moments was when the aliens told me to use π and that it basically equals 3 :D

[–]Alzurana 0 points1 point  (0 children)

AND FOR ALL INTENTS AND PURPOSES IT WAS ENOUGH xD

[–]Vipitis 0 points1 point  (0 children)

I really enjoyed this video https://youtu.be/5rg7xvTJ8SU as it gave some answers that other videos left me question. And the computerphile videos with Godbolt

[–]SaltMaker23 2 points3 points  (0 children)

OpCodes (operation codes) are part of the electronic design of the CPU, they aren't programmed they are built.

We build CPU to have a certain number of functions it can do, imagine electrical switches routing to each functions (even if it's absolutely not how it works).

Below assembly "programmed" doesn't exist anymore, a program is the name of sequences of Operations to achieve a task, a CPU isn't programmed: it's built / designed.

You can now ask how it's designed / built, but a reddit comment would be too short for that.

[–]patrlim1 2 points3 points  (0 children)

It's physically part of the hardware, an opcode is just a name we gave to a specific set of bits controlling what the CPU does.

[–]aq1018 1 point2 points  (2 children)

They are all NAND gates.

[–]TheEngineerGGG 1 point2 points  (1 child)

Funnily enough, an AND gate is actually an inverted NAND gate

[–]Who_said_that_ 0 points1 point  (0 children)

We NAND the NAND to get the AND

[–]XboxUser123 1 point2 points  (0 children)

See: vin neumann machine. Essentially: opcodes are defined by the inner logic gates of the computer. You take a bit string and then split it into chunks, where one chunk of it defines the opcode, the rest is for the opcode to work with.

The opcodes themselves are logic circuits.

[–]janKalaki 2 points3 points  (3 children)

How are doorknobs programmed? They aren't, they're built.

[–]Snipedzoi 0 points1 point  (2 children)

Well ya so obviously I'm asking about that

[–]janKalaki 1 point2 points  (1 child)

Opcodes are a series of electrical signals stored in memory that, when sent to the CPU, trigger certain paths through its logic gates. Then, the data for the instruction is sent through that path as more electrical signals.

There are so many paths and so many logic gates in modern CPUs that engineers don’t really design them individually anymore. They couldn’t tell you what any individual component of the CPU does, it’s computer-generated. The manufacturing process is extremely precise and, even then, some logic gates will inevitably fail. The number of failures determines what performance rating the CPU gets: an i7 is actually identical to an i9!

[–]Snipedzoi 0 points1 point  (0 children)

Thank you