Corewar documentation 1.0.0
Loading...
Searching...
No Matches
myop.h
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2023
3** Corewar
4** File description:
5** The header file of the op
6*/
12#ifndef _OP_H_
13 #define _OP_H_
14
15 #define MEM_SIZE (6 * 1024)
16 #define IDX_MOD 512 /* modulo of the index */
17 #define MAX_ARGS_NUMBER 4 /* this may not be changed 2^*IND_SIZE */
18
19 #define COMMENT_CHAR '#'
20 #define LABEL_CHAR ':'
21 #define DIRECT_CHAR '%'
22 #define SEPARATOR_CHAR ','
23 #define LABEL_CHARS "abcdefghijklmnopqrstuvwxyz_0123456789"
24
25 #define NAME_CMD_STRING ".name"
26 #define COMMENT_CMD_STRING ".comment"
27
28 /*
29 ** regs
30 */
31 #define REG_NUMBER 16 /* r1 <--> rx */
32
33 /*
34 **
35 */
36typedef char args_type_t;
37
38 #define T_REG 1 /* register */
39 #define T_DIR 2 /* direct (ld #1,r1 put 1 into r1) */
40 #define T_IND 4 /* indirect always relative
41 * (ld 1,r1 put what's in the address (1+pc) into r1 (4 bytes )) */
42 #define T_LAB 8 /* LABEL */
43
44typedef struct op_s {
45 char *mnemonique;
46 char nbr_args;
47 args_type_t type[MAX_ARGS_NUMBER];
48 char code;
49 int nbr_cycles;
50 char *comment;
51} op_t;
52
53 /*
54 ** size (in bytes)
55 */
56 #define INSTRUCTION_ID_SIZE 1
57 #define CODING_BYTE_SIZE 1
58 #define IND_SIZE 2
59 #define DIR_SIZE 4
60 // #define REG_SIZE DIR_SIZE
61 #define REG_SIZE 1
62
63 /*
64 ** coding_byte
65 */
66 #define NO_CODE 0b00
67 #define REG_CODE 0b01
68 #define DIR_CODE 0b10
69 #define IND_CODE 0b11
70 #define DIR_IND_CODE 0b100
71
72 /*
73 ** op_tab
74 */
75extern op_t op_tab[];
76
77 /*
78 ** header
79 */
80 #define PROG_NAME_LENGTH 128
81 #define COMMENT_LENGTH 2048
82 #define COREWAR_EXEC_MAGIC 0xea83f3
83
84typedef struct header_s {
85 int magic;
86 char prog_name[PROG_NAME_LENGTH + 1];
87 int prog_size;
88 char comment[COMMENT_LENGTH + 1];
89} header_t;
90
91 /*
92 ** live
93 */
94 #define CYCLE_TO_DIE 1536 /* number of cycle before being declared dead */
95 #define CYCLE_DELTA 5
96 #define NBR_LIVE 40
97
98#endif
op_t op_tab[]
The op_tab containing the informations of the instructions.
Definition op.c:18
Definition myop.h:83
Definition myop.h:43