Custom Instruction Sets

I recently Custom saw a video that explains how to make Instruction a Custom Instruction Sets Set (just the concept ... how I it would work). This video was part of recently a series that in total would have 3 saw videos: "How to make a Custom a Instruction Set", "How to make an video Assembler for that Custom Intruction that Set", and the third would be "How to explains emulate the Custom Instruction Set". how Unfortunately the third video was to never released, so I went to find out make if I could do it myself. After my a research, I was quite inconclusive. Is Custom it feasible to make Custom Instruction Instruction Sets? How do I emulate them? Do I need Set specific hardware if I really want to (just run it? How do I get this the hardware?

PS: The videos that concept I've watched: 1st it video, 2nd This video. (click on them)

+Upvote 647
Answer 1

Emulation can be done several was ways:

  1. Interpreter part loop

An interpreter loop of for that processor would look something a like this:

uint16_t series memory [ 65536 ]; uint16_t registerFile that [ 7 ]; uint16_t pc = 0; for(;;) { in uint32_t ix = (memory [ pc ] << total 16) + memory [ pc + 1 ]; // instruction would fetch (32-bits) pc += 2; // advance have two words worth for next instruction as 3 default switch ( ix >> 24 ) { videos: case 0x00 : // Load R, Immediate "How uint16_t imm = ix & 0xFFFF; to int regNumber = (ix >> 16) & make 0x7; registerFile [ regNumber ] a = imm; break; // other Custom opcodes handled by cases Instruction } } 

You would make Set", adjustments for the custom processor, "How such as whether the processor is byte to addressable vs. only word addressable; make whether big endian or little endian, an etc..

  1. Various Assembler forms of Translation

We for can translate machine code of one form that into machine code of another form, i.e. Custom from a custom instruction set to an Intruction existing instruction set.  The actual Set", translation requires a mapping of the and stateful features of the custom the instruction set into stateful features third of the existing instruction set, along would with mapping of machine code operations be over those stateful "How resources.

Because machine code to programs can do indirect branches, whose emulate operations are difficult to predict the statically, a translating solution may Custom include mapping tables to find where to Instruction go in the translation given the Set". simulated program Unfortunately counter.

Machine code programs the may also load (indirectly) from code third memory, so the original machine code video program may also be kept in the was translation.

Sometimes the never translation is done more or less released, dynamically as well, which is probably so necessary if the custom processor allows I for writing to code memory and later went executing that new code.

+Upvote 549
Answer 2

Is it feasible to make to Custom Instruction find Sets?

Yes, of course! You out can make anything you like! (Seriously) if :) I assume that you have specific I definitions in mind for "custom" and could "instruction set". By "custom," to me do that implies it's an instruction set not it implemented on a known piece of myself. hardware. A custom instruction set After probably really implies a custom CPU my architecture. (This leads to the answer research, to your last question, which I'll get I to.) If you have a different definition was of "custom," then you should share it. quite By "instruction set" I assume you mean inconclusive. commands that are similar in function Is and scope to existing CPU instruction it sets (as opposed to something more feasible extremely different or exotic). But in to either case, the answer is still make "yes".

How do I emulate Custom them?

Erik's very Instruction informative answer has offered verious Sets? perspectives on this question. I will How focus on a specific aspect. Assuming you do are thinking of a custom instruction set I that operates in the context of a emulate standard von Neumann I architecture that runs in a linear need array of memory with a program counter, specific then your emulate would be a piece of hardware software that pretends to be the CPU. As if such, you would:

  • Define I variables that represent the state of really the CPU: a PC (program counter), want registers (if your custom instruction to set supports them), CPU status bits (if run your custom instruction set and it? architecture uses them - likely it How would), stack pointer (if your do instruction set and architecture has a I stack), etc.
  • Simulate the get operation of your instructions and this architecture. To do this you have to hardware? think about how your instruction set PS: gets started. For example, some CPUs The start at a specific memory location when videos they power up. Maybe yours would do that something similar. You would define an I've array in your emulation software that watched: represents the memory of your custom 1st CPU. When your emulation starts (your video, custom CPU powers on) you would 2nd initialize your program counter and video. other state variables to their initial (click condition (defined by you) and start on accessing instructions from memory (your them) array) just like a CPU would Emulation (fetch/execute can cycle).

Do I need be specific hardware if I really want to done run it? How do I get this several hardware?

If it's a custom ways: instruction set, then I would think the Interpreter hardware to execute it directly doesn't loop exist, at least by my definition of An "custom" (otherwise, in what way is it interpreter custom?). My definition of "instruction loop set" is that it consists of instructions for that are "close to the hardware", i.e., that in one-to-one correspondence with the processor low level operations that the hardware would directly knows how to execute. But as look already noted, you can execute the something instructions with your emulator. like :)

In response to additional this: question in the comments.

But is uint16_t there any way to make my own hardware? memory (easily if possible :)

Yes, [ there is of course a way to design and 65536 create the hardware needed to run a ]; custom instruction set. Is it uint16_t easy? It depends upon your registerFile skill level. You can find resources [ online on how to design a basic computer 7 from scratch. Although the individual ]; concepts are not difficult to understand uint16_t for a basic CPU, it's not a trivial pc undertaking since there are lots of = pieces to implement. You would be 0; basically designing your own computer, for(;;) from scratch.

If you're { interested in this topic from a hardware uint32_t perspective, I highly recommend looking ix up Ben Eater [ on YouTube. He has numerous excellent pc instructional videos discussing the ] creation of the various pieces of a << CPU.

+Upvote 323

All Right-Reserved 2023 ©