Skip to content
This repository was archived by the owner on Sep 10, 2025. It is now read-only.

Commit 8945ecb

Browse files
committed
Fixed comments on functions
1 parent f093b4c commit 8945ecb

1 file changed

Lines changed: 106 additions & 35 deletions

File tree

‎opcode/opcode.go‎

Lines changed: 106 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,115 @@ package opcode
22

33
var (
44
// EXIT is our first opcode.
5-
// The rest follow, grouped by functionality.
6-
EXIT = 0x00
7-
INT_STORE = 0x01
8-
INT_PRINT = 0x02
9-
INT_TOSTRING = 0x03
10-
INT_RANDOM = 0x04
11-
JUMP_TO = 0x10
12-
JUMP_Z = 0x11
13-
JUMP_NZ = 0x12
14-
XOR_OP = 0x20
15-
ADD_OP = 0x21
16-
SUB_OP = 0x22
17-
MUL_OP = 0x23
18-
DIV_OP = 0x24
19-
INC_OP = 0x25
20-
DEC_OP = 0x26
21-
AND_OP = 0x27
22-
OR_OP = 0x28
23-
STRING_STORE = 0x30
24-
STRING_PRINT = 0x31
5+
EXIT = 0x00
6+
7+
// INT_STORE allows an integer to be stored in a register.
8+
INT_STORE = 0x01
9+
10+
// INT_PRINT is used to print the integer contents of a register.
11+
INT_PRINT = 0x02
12+
13+
// INT_TOSTRING converts an integer-register value to a string.
14+
INT_TOSTRING = 0x03
15+
16+
// INT_RANDOM generates a random number.
17+
INT_RANDOM = 0x04
18+
19+
// JUMP_TO is an unconditional jump.
20+
JUMP_TO = 0x10
21+
22+
// JUMP_Z jumps if the Z-flag is set.
23+
JUMP_Z = 0x11
24+
25+
// JUMP_NZ jumps if the Z-flag is NOT set.
26+
JUMP_NZ = 0x12
27+
28+
// XOR_OP performs an XOR operation against to registers.
29+
XOR_OP = 0x20
30+
31+
// ADD_OP performs an ADD operation against to registers.
32+
ADD_OP = 0x21
33+
34+
// SUB_OP performs an MINUS operation against to registers.
35+
SUB_OP = 0x22
36+
37+
// MUL_OP performs a MULTIPLY operation against to registers.
38+
MUL_OP = 0x23
39+
40+
// DIV_OP performs a DIVIDE operation against to registers.
41+
DIV_OP = 0x24
42+
43+
// INC_OP increments the given register by one.
44+
INC_OP = 0x25
45+
46+
// DEC_OP decrements the given register by one.
47+
DEC_OP = 0x26
48+
49+
// AND_OP performs a logical AND operation against to registers.
50+
AND_OP = 0x27
51+
52+
// OR_OP performs a logical OR operation against to registers.
53+
OR_OP = 0x28
54+
55+
// STRING_STORE stores a string in a register.
56+
STRING_STORE = 0x30
57+
58+
// STRING_PRINT prints the string contents of a register.
59+
STRING_PRINT = 0x31
60+
61+
// STRING_CONCAT joins two strings.
2562
STRING_CONCAT = 0x32
63+
64+
// STRING_SYSTEM executes the system binary stored in the given string-register.
2665
STRING_SYSTEM = 0x33
27-
STRING_TOINT = 0x34
28-
CMP_REG = 0x40
66+
67+
// STRING_TOINT converts the given string-register contents to an int.
68+
STRING_TOINT = 0x34
69+
70+
// CMP_REG compares two registers.
71+
CMP_REG = 0x40
72+
73+
// CMP_IMMEDIATE compares a register contents with a number.
2974
CMP_IMMEDIATE = 0x41
30-
CMP_STRING = 0x42
31-
IS_STRING = 0x43
32-
IS_INTEGER = 0x44
33-
NOP_OP = 0x50
34-
REG_STORE = 0x51
35-
PEEK = 0x60
36-
POKE = 0x61
37-
MEMCPY = 0x62
38-
STACK_PUSH = 0x70
39-
STACK_POP = 0x71
40-
STACK_RET = 0x72
41-
STACK_CALL = 0x73
42-
TRAP_OP = 0x80
75+
76+
// CMP_STRING compares a register contents with a string.
77+
CMP_STRING = 0x42
78+
79+
// IS_STRING tests if a register contains a string.
80+
IS_STRING = 0x43
81+
82+
// IS_INTEGER tests if a register contains an integer.
83+
IS_INTEGER = 0x44
84+
85+
// NOP_OP does nothing.
86+
NOP_OP = 0x50
87+
88+
// REG_STORE stores the contents of one register in another.
89+
REG_STORE = 0x51
90+
91+
// PEEK reads from memory.
92+
PEEK = 0x60
93+
94+
// POKE sets an address-content.
95+
POKE = 0x61
96+
97+
// MEMCPY copies a region of RAM.
98+
MEMCPY = 0x62
99+
100+
// STACK_PUSH pushes the given register-contents onto the stack.
101+
STACK_PUSH = 0x70
102+
103+
// STACK_POP retrieves a value from the stack.
104+
STACK_POP = 0x71
105+
106+
// STACK_RET returns from a CALL
107+
STACK_RET = 0x72
108+
109+
// STACK_CALL calls a subroutine.
110+
STACK_CALL = 0x73
111+
112+
// TRAP_OP invokes a CPU trap.
113+
TRAP_OP = 0x80
43114
)
44115

45116
// Opcode is a holder for a single instruction.

0 commit comments

Comments
 (0)
⌂ 换网址