Add a hashtable that contains information about the instructions

This commit is contained in:
XOR 2023-04-14 16:55:57 +02:00
parent 3ce1b99f26
commit e81e0a6e94
2 changed files with 93 additions and 0 deletions

View file

@ -0,0 +1,25 @@
#ifndef _INSTRUCTION_TABLE_H_
#define _INSTRUCTION_TABLE_H_
#include "../header/shash/shash.h"
#include <sys/types.h>
// Create a hashtable that contains
shash_hashtable_t create_instruction_information_hastable(void);
typedef struct
{
unsigned int requires_adress;
unsigned int supports_adress_label;
u_int8_t opcode;
} instruction_information_t;
typedef struct
{
char *name;
unsigned int requires_adress;
unsigned int supports_adress_label;
u_int8_t opcode;
} instruction_information_config_t;
#endif

68
src/instruction_table.c Normal file
View file

@ -0,0 +1,68 @@
#include "../header/instruction_table.h"
#include "../header/shash/shash.h"
#include <stdio.h>
shash_hashtable_t create_instruction_information_hastable(void)
{
shash_hashtable_t instruction_table;
// Change this code if you want to configure changes to the instruction format
instruction_information_config_t config[] = {
{.name = "INC",
.requires_adress = 1,
.supports_adress_label = 0,
.opcode = 0b0001},
{.name = "OUT",
.requires_adress = 1,
.supports_adress_label = 0,
.opcode = 0b0010},
{.name = "LDA",
.requires_adress = 1,
.supports_adress_label = 0,
.opcode = 0b0011},
{.name = "STA",
.requires_adress = 1,
.supports_adress_label = 0,
.opcode = 0b0100},
{.name = "INC",
.requires_adress = 0,
.supports_adress_label = 0,
.opcode = 0b0101},
{.name = "DEC",
.requires_adress = 0,
.supports_adress_label = 0,
.opcode = 0b0110},
{.name = "JPP",
.requires_adress = 1,
.supports_adress_label = 1,
.opcode = 0b0111},
{.name = "JPZ",
.requires_adress = 1,
.supports_adress_label = 1,
.opcode = 0b1000},
{.name = "JPN",
.requires_adress = 1,
.supports_adress_label = 1,
.opcode = 0b1001},
{.name = "JPU",
.requires_adress = 1,
.supports_adress_label = 1,
.opcode = 0b1010},
{.name = "EOJ",
.requires_adress = 0,
.supports_adress_label = 0,
.opcode = 0b1011},
{0}
};
return instruction_table;
}