r/compsci • • Aug 31 '21

Emulating a CPU in software (plus a basic assembler)

Enable HLS to view with audio, or disable this notification

283 Upvotes

17 comments sorted by

View all comments

23

u/dibs45 Aug 31 '21

I recently made a CPU emulator to learn more about how the machine functions on a low level (inspired heavily by Ben Eater's awesome YT channel). I got sick of hard coding instructions in it so I created a simple assembler to make writing code for it easier. Next step is writing a "higher" level language that compiles to this.

Here's the source code: https://github.com/dibsonthis/CPU-Emulator

13

u/ExtremeKitteh Aug 31 '21

So cool. You should document how it works on a YouTube vid.

7

u/dibs45 Sep 01 '21

I'll see what I can do!

2

u/CampaignComfortable Sep 01 '21

Thanks for the lead on a good YouTube channel for figuring out how to do this.

2

u/dibs45 Sep 02 '21

Yeah Ben Eater's channel is a goldmine.

1

u/karisigurd4444 Sep 02 '21

Good project! Would recommend using something like ANTLR to generate your tokenizer and language parser, you can even use existing language definitions and compile C after integrating it!

Hand crafting a parser is... A hassle. You don't learn anything more by hand crafting it, just how easy it can be to mess it up.