DEV Community

Cover image for What is keeping you from dabbling in writing Hardware ?
YJDoc2
YJDoc2

Posted on

What is keeping you from dabbling in writing Hardware ?

Let's face it, if you are writing any program, in any language : you need hardware to run it.

If you write C / C++ / Rust code it will compile to binary which will execute inside you processor (eventually) and if you use python / JS it will run on top of their interpreters, which themselves run on the hardware. One way or other you will have to use hardware to execute your code. I hope we can agree on this 😉 😉

Hardware such as CPU does some really amazing things , latest CPUs have pipelined processing, so that they can run multiple instructions at the same time, and also logic to detect if the next instructions can run at the same time or not. They have several 128 bit-and-more registers which can process floating numbers and strings crazy fast, parallely and with various options : Do you know there is an instruction in x86 instruction set ( one used by common Intel and AMD CPUs) that can check if a substring is present or not in given string?

a complex but processor board

I agree that at the beginning it can be hard, even outright scary to get into such low level of systems, where everything is in binary and you have to take into consideration the things that you didn't know existed. But as with any other programming / coding / computer related stuff, I think it can get more manageable, if not easy, if one works with it more.

Think about the first website or app or any project that you made, and how complex or technical it seemed at first, and how hard it seems after having done it several times after. The more you play with it, the more you try and make mistakes, I feel the better you get at it.

So, what is stopping you from getting into something so cool as hardware ?

In my case :

  • To buy and work with actual Hardware, like Raspberry Pi, involves some cost, and even then I'm still working on an API abstraction of some libraries (usually)
  • For designing actual hardware at the low level, current options usually involve VHDL or Verilog like softwares, and it can get pretty complex pretty soon, even to implement something very simple. Don't get me wrong, those s/w are pretty amazing, they can Optimize the circuits you wrote,and can be used to actually synthesize stuff that can be etched onto FPGAs , Which is pretty cool! But for a beginner who want to write few chips, the overhead can be tedious.

So, mainly because of the point 2, I am currently working on a library in Rust which will make it easier to write s/w emulated h/w in Rust. The complete logic of your chip will be in Rust, you can access files and stuff if you want, and do anything that Rust can do. The way I'm thinking, it will be as simple as writing a struct/class, annotating which pins are input, output and a function to operate what the chip will actually do based on the values of those pins.

Now this won't help you write Intel Pentium in 100 lines of code. Even emulators for Intel 8086, which was released in 1987, take about 2000-5000 lines of code (I would know, I have written one).

That said, this will allow you to ignore how to connect pins of various chips or how to write interface to connect chips and allow you to focus on the logic of the chip, like how 4-bit binary adders add two numbers or how ring counters actually count, or how a CPU actually reads the data from RAM and so on. This also aims to make them sharable so you can take RAM someone else wrote and interface it with you CPU, just like you would use different modules or packages for a project.

Even though I am writing it in Rust, the logic behind it does not depend on Rust, so one can easily do the same in Python or JS, and maybe even use Rust components with them.

I will share it once the things are done, but in the meantime I would like to know what is keeping you form dabbling in writing s/w emulated h/w. Maybe I can add features which will solve your issues too. Let me know in the comments!


PS : if you want to know when I publish the library, follow me 😉 you can unfollow after I publish it , I won't mind 😄

Thank you!

Note : all images are taken from google images search, and are not mine.

Top comments (2)

Collapse
 
nsengupta profile image
Nirmalya Sengupta

Following you, out of interest.

My interaction with chips ended at Intel 8085, about 3 decades back (using C and a bit of ASM); therefore, my knowledge about this world is severely limited. However, I claim to understand how complicated a S/W emulator for H/W can become, when implemented. Yours is an appreciable initiative.

Will be keen to know where you are on this project.

Collapse
 
yjdoc2 profile image
YJDoc2

Hey @nsengupta Thanks for commenting! Happy to hear that you are interested in this.

As I had written in a blogpost after this one I have released the first version of this, along with an web-based demo which you can run right in your browser. The post has links for the github repo as well as the demo.

Also as you had mentioned intel 8085, I think you'd also be interested in an 8086 emulator I have built : check the web version or you can read more about in its blogpost

Hope this helps!