Tips for writing a simple processor emulator

I've already googled speci i4004, I'm sitting here studying it.

Tell me how best to do this?

I will write a generator that will accept a scheme containing:

  • Descriptions of the byte size (yes, it is not 8-bit everywhere), the word size.
  • Number, size, and register names
  • A set of operations, with a description of the opcodes, and then the implementation of these operations.
  • The duration of each operation.
  • Available memory.

According to this scheme code will be generated to perform operations, read opcodes.

I haven't finished reading the spec yet, whether there were interrupts in i4004, but I want to make interrupt support in this emulator. How to make them better?

Author: Nicolas Chabanovsky, 2011-02-12

2 answers

In its simplest form, it is done this way.

  1. According to the processor scheme, the necessary blocks are defined (general-purpose registers, flag registers, instruction counters, etc.) and code objects are created for them.
  2. The method of storing machine code in memory is selected, for example, a simple array.
  3. The method of decoding machine codes is selected, for example, a transition table or a function table.
  4. An infinite loop is implemented in which the table executes machine code.

As a programming exercise, this will be quite enough. If you need to do something more serious, you should study the code of existing emulators, for example, qemu.

Example of the implementation of ARM processor emulator on Google code.

 0
Author: stanislav, 2011-02-12 20:26:37

Each command is executed in several stages:

  1. Extracting the opcode from RAM.
  2. Decoding.
  3. Retrieving operands from RAM.
  4. Performing the operation.
  5. Saving the result.

You can check the status of the interrupt register( or whatever it is called) after each stage. In addition, this scheme decomposes the system well into blocks :-)

 0
Author: psyhitus, 2011-02-13 06:04:06