# I got a cool idea for a kinda-emulator and i need a bit of help

How do i implement a simple CPU in Snap, as well as Registers, as Ram and Rom?
I know the fundamentals from my friend giving me a crash course on it.
To start, how do i implement all this stuff using Hexadecimal and Binary, while simulating the limitations of said formats?

i think first you’ll need to find an instruction set. you could use something like arm make up your own. and you could represent memory as a list of numbers, with each item in the list representing a number of bits. the bitwise operators library would be useful for this.

Yeah, the idea was to make my own but i'll take a look at ARM's now that you gave me the idea. What do you mean by

...and you could represent memory as a list of numbers, with each
item in the list representing a number of bits...

? Do you mean just represent everything as a list of ones and zeroes? If so, i'd much rather use hexadecimal.

I remember trying to make something like this. Actually, I have made an emulator that emulates electronic components. It's not a full emulator, but, anyways, I basically mapped out all the data of the components and so this data can be useful if you want to program in the logic to make the chip components actually work.

hexadecimal is just a representation of a “number”. it’s much faster to use numbers directly instead of having to parse hex into an integer every time a number is needed.

i once thought of making an array of raw memory as an array of true/false values. but in retrospect, this method would be pretty slow since i needed to implement my own adder in snap code. i don’t think cpus process things bit by bit anyway, i think they do it by their word size (e.g. 8 bit, 16 bit, 32 bit).

what i mean is each memory address would hold an integer of an arbitrary size. for example an 8 bit integer. of course they would really be floating points, but you could constrain the value to be like an 8 bit value by using the modulo operator with 255.

If you've not done something like this before, i'd recommend trying to make a Little Man Computer emulator first

Its a very good starter project for this sort of thing

What?

Also CHIP-8

build a list of logic gates that interact with each other