Live data from Hacker News

How a CPU works: Bare metal C on my RISC-V toy CPU

florian.noeding.com

11–20 of 39 posts

Re: How a CPU works: Bare metal C on my RISC-V toy CPU

#11
post #6
post #2

I always wanted to understand how a CPU works, how it transitions from one instruction to the next and makes a computer work. So I thought: let's implement one and run a C program on it.

Check out some videos by Ben Eater on Youtube

Ben Eater routinely makes me feel ashamed of how awful my breadboard wiring looks. Fantastic videos.

Re: How a CPU works: Bare metal C on my RISC-V toy CPU

#14
post #6
post #2

I always wanted to understand how a CPU works, how it transitions from one instruction to the next and makes a computer work. So I thought: let's implement one and run a C program on it.

Check out some videos by Ben Eater on Youtube

Unless your name is Ben, in which case I'd advise caution.

Re: How a CPU works: Bare metal C on my RISC-V toy CPU

#17

This gets brought up every time the topic shows up but https://www.nand2tetris.org is a course that abstracts how a computer works, and is worth checking out

Is there a version of something like this that’s purely software?

Like, emulate gates and keep building bigger pieces until you have a function that’s a CPU. Etc.

I guess I’m thinking a bit more lower level than an emulator where you implement an opcode using normal capabilities of your language of choice.

I guess TFA is pretty close to this in ways, too.

Re: How a CPU works: Bare metal C on my RISC-V toy CPU

#18
post #2

I always wanted to understand how a CPU works, how it transitions from one instruction to the next and makes a computer work. So I thought: let's implement one and run a C program on it.

This is written for young people, but still accurate: Code: The Hidden Language of Computer Hardware and Software by Charles Petzold

Link: https://www.amazon.com/Code-Language-Computer-Hardware-Softw...

It's got a very slow, methodical onramp with a lot of diagrams and a light, breezy style. You end up building a (very simple) computer in the end, including instruction processing.

Re: How a CPU works: Bare metal C on my RISC-V toy CPU

#19

This gets brought up every time the topic shows up but https://www.nand2tetris.org is a course that abstracts how a computer works, and is worth checking out

Is there a version of something like this that’s purely software? Like, emulate gates and keep building bigger pieces until you have a function that’s a CPU. Etc. I guess I’m thinking a bit more lower level than an emulator where you implement an opcode using normal capabilities of your language of choice. I guess TFA is pretty close to this in ways, too.

Yeah. There this book which uses Haskell based Clash to build up simple CPUs, a VGA controller and other peripherals.

hardcover:

https://www.lulu.com/shop/gerg%C5%91-%C3%A9rdi/retrocomputin...

or digital:

https://leanpub.com/retroclash/

Re: How a CPU works: Bare metal C on my RISC-V toy CPU

#20

Earlier quoted context omitted.

Is there a version of something like this that’s purely software? Like, emulate gates and keep building bigger pieces until you have a function that’s a CPU. Etc. I guess I’m thinking a bit more lower level than an emulator where you implement an opcode using normal capabilities of your language of choice. I guess TFA is pretty close to this in ways, too.

Yeah. There this book which uses Haskell based Clash to build up simple CPUs, a VGA controller and other peripherals. hardcover: https://www.lulu.com/shop/gerg%C5%91-%C3%A9rdi/retrocomputin... or digital: https://leanpub.com/retroclash/

Oh that’s exactly what I was hoping for! Thank you!
Post reply on HN