-
Notifications
You must be signed in to change notification settings - Fork 0
/
design.txt
128 lines (97 loc) · 3.96 KB
/
design.txt
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
ARCHITECTURE:
Word size = 32 bit
REGISTERS: 16 word sized REGISTERs, 12 General Use, Flags, Program Counter, Base Pointer and STACK Pointer
GENERAL USE:
R0 - Accumulator, by standard stores return values.
R1 - Accumulator.
FLAGS:
the FLAGS are set after a ADD, SUB, AND, OR, XOR and CMP INSTRUCTION.
ZF - indicates wether the latest calculation resulted in 0.
NF - indicates wether the most signifact bit was set in the last calculation.
CF - indicates wether the last calculation has a carry.
OF - indicates wether the latest calculation overflowed.
MEMORY: 2^16 addresses, all word sized.
STACK: 0x0000 - 0x1fff
Heap: 0x2000 - 0x5fff
Data Segment: 0x6000 - 0x7fff
Code Segment: 0x8000 - 0xffff
INSTRUCTIONS:
The INSTRUCTIONS are the representations of OPCODES in an assembly file (.ec file).
an INSTRUCTION may correspond directly to an OPCODE or may be translated to a variety of OPCODES
depending on arguements provided.
The corresponding OPCODE for an INSTRUCTION will start with the INSTRUCTION mnemonic.
END => END
NOP => NOP
PUSH => PUSHI, PUSHL, PUSHR
POP => POP
LDR => LDR
STR => STR
MOV => MOVRI, MOVRL, MOVRR
(The same translations apply to ADD, SUB, MUL, IMUL, DIV, IDIV, AND, OR, XOR)
JMP => JMP
JNZ => JNZ
JZ => JZ
JG => JG
JGE => JGE
JL => JL
JLE => JLE
JA => JA
JAE => JAE
JB => JB
JBE => JBE
OPERATIONS:
The OPERATIONS are the machine specification for the assembly lagnuage INSTRUCTIONS,
for exmaple MOVRI is the specific OPERATION for a MOV INSTRUCTION with a REGISTER as destination and an IMMEDIATE VALUE as source.
The INSTRUCTION SET is a RISC ISA, meaning there is no interaction with memory besides loading from it and jumping to it.
Word sized, design:
32 bits
|----------------------------------------------------------------|
| | 1st operard | immediate |
| opcode | REGISTER | 20 bit value |
| | | |
|----------------------------------------------------------------|
8 bits 4 bits 20 bits
Note that some INSTRUCTIONS may have an OPCODE for larger than 20bit values that will include a jump to the next ADDRESS stored in the CODE SEGMENT.
OPCODES:
END: Labels end of code
NOP: Move to next instruction
PUSH:
PUSHI: Pushes immediate value to STACK
PUSHL: Pushes 32bit value to STACK
PUSHR: Pushes value from REGISTER
POP: Pops value from STACK to REGISTER
LDR: Moves value from MEMORY ADDRESS pointed to by the 2nd operand REGISTER
to REGISTER in first operand.
STR: Stores into MEMORY ADDRESS pointed by the 1st operand REGISTER
the value stored in the 2nd REGISTER in first operand.
MOV:
MOVRI: Moves immediate value to REGISTER
MOVRL: Moves 32bit value to REGISTER
MOVRR: Moves from REGISTER to REGISTER
ADD:
ADDRI: Adds immediate value to REGISTER
ADDRL: Adds 32bit value to REGISTER
ADDRR: Adds from REGISTER to REGISTER
(Same opcodes specification for SUB, MUL and DIV instructions)
(MUL and DIV have corresponding IMUL and IDIV INSTRUCTIONS for signed calculations)
CMP:
CMPRI: Compares immediate value to REGISTER
CMPRL: Compares 32bit value to REGISTER
CMPRR: Compares from REGISTER to REGISTER
JMP: Jumps to memory address
JNZ: Jumps to memory address if ZF = 0
JZ: Jumps to memory address if ZF = 1
JG: Signed > check, works if ZF = 0 and NF = OF
JGE: Signed >= check, works if NF = OF
JL: Signed < check, works if NF != OF
JLE: Signed <= check, works if ZF = 0 or NF != OF
JA: Unsigned > check, works if CF = 0
JAE: Unsigned >= check, works if CF = 0 or ZF = 1
JB: Unsigned < check, works if CF = 1
JBE: Unsigned >= check, works if CF = 1 or ZF = 1
NOT: Logical NOT on value in REGISTER
AND:
ANDRI: Logical end between immediate value to REGISTER
ANDRL: Logical end between 32bit value to REGISTER
ANDRR: Logical end between REGISTER to REGISTER
(Same opcode specification OR and XOR instruction)