5 ms·
Comp Mark II: Simple 4-bit/1 Hz Virtual Computer
- Narishma 11y agoThat looks to be an 8-bit CPU. It has an 8-bit accumulator and instructions are encoded in 8-bits. The only 4-bit thing in there is the address space, but even that is really 2*4-bits.
- userbinator 11y agoThe architecture looks simple enough, but when I saw the source... https://github.com/gto76/comp-m2/tree/master/src https://github.com/gto76/comp-m2/tree/master/src ...that's quite a bit more code than I was expecting. https://github.com/gto76/comp-m2/blob/master/src/specific_instruction.hpp https://github.com/gto76/comp-m2/blob/master/src/specific_in... https://github.com/gto76/comp-m2/blob/master/src/specific_instruction.cpp https://github.com/gto76/comp-m2/blob/master/src/specific_in... IMHO this is a good example of how OOP can obfuscate. Over a dozen classes, all almost the same. This could easily be condensed into a single lookup table. For comparison, here is a complete 8086 emulator, and it also includes some code to emulate other hardware of the PC: https://github.com/adriancable/8086tiny/blob/master/8086tiny.c https://github.com/adriancable/8086tiny/blob/master/8086tiny...
- gjm11 11y agoIn fairness, (1) a lot of the verbosity of the code here is because of the way C++ makes you separate out declarations and definitions, and makes you declare member functions even when they are just overriding virtual member functions in a base class, and in a nicer language equivalent code would be distinctly less painful; and (2) the 8086 emulator is able to be nice and small partly because its author is very, very, very clever. (Note: author of 8086tiny is my boss.)
- w0utert 11y agoThe code is just normalized to separate each bit of functionality and each class into its own source file, which IMO can hardly be seen as a negative. Yes you could do the same in a lot less lines of code, in a single source file, but that does not necessarily mean the code would be 'better' (easier to read, debug, maintain), just shorter and easier to analyse by quickly scanning it. If someone would ever like to add more advanced features to this simulator, the advantages of the normalisation and separation of concerns will quickly outweigh the 'downside' of having a few more files than absolutely necessary.
- cbd1984 11y agoI wonder why the Makefile builds everything with -O0
- pizzaburek 11y agoIt takes too long to compile otherwise, and I didn't want people to give up during compilation... You can run 'make optimize' to use -O1