lastmjs / wasm-metal

A bare metal physical implementation of WebAssembly. That's right, a WebAssembly CPU.
MIT License
365 stars 9 forks source link

Figure out the main instruction cycles #14

Open lastmjs opened 6 years ago

lastmjs commented 6 years ago

Let's determine this right now before we go much further. Here's my initial idea:

  1. Opcode
    • fetch the opcode
  2. Parameters
    • based on the opcode, determine the number of parameters
    • Grab the parameters and push them onto the stack (registers)
  3. Compute
    • based on the opcode, grab the parameters from the stack (registers) (pop them off?)
    • based on the opcode, perform a computation and store it somewhere temporarily
  4. Result
    • Push the result onto the stack
lastmjs commented 6 years ago

@electrovir Let's figure this out before we do anything else

lastmjs commented 6 years ago

Looks like we are both agreed on an OPCODE step and a PARAMETERS step

electrovir commented 6 years ago

Registers

Assume we have the following registers (this may or may not change). Also assume we have external memory.

Naming on the last two registers is open for possible debate.

AFAIK we can't optimize out the MDR or the MAR because they are part of the general model for memory, which we want to interface with.

Instructions

Each numbered item is a clock cycle (bullets do not represent a clock cycle, just groupings of cycles or control explanations).

The Parameters instruction will always take place after the Opcode instruction (right?), thus loading the MAR can be executed at the end of the Opcode instruction.

The contents of the Compute instruction will vary based on the current operation, which is determined by the loaded opcode. The Result instruction (number 4) you included @lastmjs will be part of a given operations's clock cycles. (Not all operations have a result.)

Terminology

The following two words are interchangeable within this context, so I want to solidify how I'm using them:

Updates

electrovir commented 6 years ago

Very rough schematics for what we worked through.

diagrams