Liens utiles

String Split - How to play with strings in C

How to implement function Pointer in C Struct - Aticleworld

Pointers and 2-D arrays

TEST#1

#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef void (*pfnInstruction)(const char rgt, int registers[]);

typedef struct instruction_t {
  char* key;
  pfnInstruction fnInstruction;
} Instruction;

void mov(const char rgt, int registers[]) {
  
}

void inc(const char rgt, int registers[]) {
  
}

void dec(const char rgt, int registers[]) {
  
}

void jnz(const char rgt, int registers[]) {
  
}

void simple_assembler (size_t n, const char *const program[n], int registers[])
{
  char delim[] = " ";
  Instruction instructions[4];
  Instruction* movInstr = NULL;
  Instruction* incInstr = NULL;
  Instruction* decInstr = NULL;
  Instruction* jnzInstr = NULL;
  
  movInstr = malloc(sizeof(Instruction));
  if(movInstr == NULL) exit(-1);
  movInstr->key = "mov";
  movInstr->fnInstruction = &mov;
  instructions[0] = *movInstr;
  incInstr = malloc(sizeof(Instruction));
  if(incInstr == NULL) exit(-1);
  incInstr->key = "inc";
  incInstr->fnInstruction = &inc;
  instructions[1] = *incInstr;
  decInstr = malloc(sizeof(Instruction));
  if(decInstr == NULL) exit(-1);
  decInstr->key = "dec";
  decInstr->fnInstruction = &dec;
  instructions[2] = *decInstr;
  jnzInstr = malloc(sizeof(Instruction));
  if(jnzInstr == NULL) exit(-1);
  jnzInstr->key = "jnz";
  jnzInstr->fnInstruction = &jnz;
  instructions[3] = *jnzInstr;
  
  for(unsigned i = 0; i < n; ++i) {
    char *ptr = strtok(program[i], delim);
    while(ptr != NULL) {
      printf("%s\\n", ptr);
      ptr = strtok(NULL, delim);
    }
  }
}