-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetting.c
More file actions
75 lines (69 loc) · 4.07 KB
/
setting.c
File metadata and controls
75 lines (69 loc) · 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "setting.h"
/* =========================================================================
* global vars assignment
* ========================================================================= */
/**
* all the reserved words of the assembly language
* */
char *reserved_words[] = {"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
".data", ".string", ".entry", ".extern", ".define",
"mov", "cmp", "add", "sub", "lea",
"not", "clr", "inc", "dec", "jmp", "bne", "red", "prn",
"jsr", "rts", "hlt",
"mcr", "endmcr", ""};
/**
* Operation names array
*
* @note each operation name is stored at the index corresponding to its
* opcode.
*/
char *operation_names[NUM_OF_OP] = {"mov", "cmp", "add", "sub", "not", "clr",
"lea", "inc", "dec", "jmp", "bne", "red",
"prn", "jsr", "rts", "hlt"};
/**
* @brief Table defining the addressing modes for each operation.
*
* Defines the addressing modes supported by each assembler operation.
* Each row corresponds to an operation, with columns indicating
* supported addressing modes for source and target operands.
*
*/
unsigned int addr_mode_table[NUM_OF_OP][3] =
{{MOV, all_mode, symbol_n_index_n_reg}, /* | 1111 | 0111 | */
{CMP, all_mode, all_mode}, /* | 1111 | 1111 | */
{ADD, all_mode, symbol_n_index_n_reg}, /* | 1111 | 0111 | */
{SUB, all_mode, symbol_n_index_n_reg}, /* | 1111 | 0111 | */
{NOT, no_operand, symbol_n_index_n_reg}, /* | - | 0111 | */
{CLR, no_operand, symbol_n_index_n_reg}, /* | - | 0111 | */
{LEA, symbol_n_index, symbol_n_index_n_reg}, /* | 0110 | 0111 | */
{INC, no_operand, symbol_n_index_n_reg}, /* | - | 0111 | */
{DEC, no_operand, symbol_n_index_n_reg}, /* | - | 0111 | */
{JMP, no_operand, symbol_n_reg}, /* | - | 0101 | */
{BNE, no_operand, symbol_n_reg}, /* | - | 0101 | */
{RED, no_operand, symbol_n_index_n_reg}, /* | - | 0111 | */
{PRN, no_operand, all_mode}, /* | - | 1111 | */
{JSR, no_operand, symbol_n_reg}, /* | - | 0101 | */
{INC, no_operand, no_operand}, /* | - | - | */
{INC, no_operand, no_operand}}; /* | - | - | */
/* --------------------------------------------------------------------
* | operator | scr operand | target operand |
* |--------------------|-----------------------|-----------------------|
* | addressing mode | imm | sym | ind | reg | imm | sym | ind | reg |
* |--------------------|-----+-----+-----+-----|-----+-----+-----+-----|
* | mov, add, sub | X | X | X | X | | X | X | X |
* |--------------------|-----+-----+-----+-----|-----+-----+-----+-----|
* | cmp | X | X | X | X | X | X | X | X |
* |--------------------|-----+-----+-----+-----|-----+-----+-----+-----|
* | lea | | X | X | | | X | X | X |
* |--------------------|-----+-----+-----+-----|-----+-----+-----+-----|
* | not, clr, inc, dec | | | X | X | X |
* |--------------------|-----+-----+-----+-----|-----+-----+-----+-----|
* | jmp, bne, jsr | | | X | | X |
* |--------------------|-----+-----+-----+-----|-----+-----+-----+-----|
* | red | | | X | X | X |
* |--------------------|-----+-----+-----+-----|-----+-----+-----+-----|
* | prn | | X | X | X | X |
* |--------------------|-----+-----+-----+-----|-----+-----+-----+-----|
* | rts, hlt | | |
* ----------------------------------------------------------------------
* */