@@ -16,8 +16,8 @@ Commands:
16
16
| :----------:| -------------|
17
17
| LITERAL | Push next 4 bytes |
18
18
| LITERAL_ARRAY | Get x from next 4 bytes; Push x sets of 4 bytes - temporary |
19
- | LOAD | Pop a; Push RAM[ a] |
20
- | STORE | Pop b; Pop a; RAM[ b] = a |
19
+ | LOAD ; LOAD_ARG ; LOAD_LCL | Pop a; Push RAM[ a] |
20
+ | STORE ; STORE_LCL | Pop b; Pop a; RAM[ b] = a |
21
21
| ADD | Pop b; Pop a; Push a + b |
22
22
| SUB | Pop b; Pop a; Push a - b |
23
23
| LESS | Pop b; Pop a; Push a < b |
@@ -26,19 +26,38 @@ Commands:
26
26
| EQUALS | Pop b; Pop a; Push a == b |
27
27
| JMP | Pop a; goto a; |
28
28
| JMP_IF | Pop b; Pop a; if a goto b |
29
+ | CALL | put current state in a stack frame; store RTN; Pop a; goto a; |
30
+ | RETURN | Restore to previous stack frame; append working stack; goto RTN |
29
31
| PRINT | Pop x; for x Print Pop - temporary, will be a library function based on null terminated strings |
30
32
| PRINT_INT | Pop a; Print string of a |
31
- | PRINT_ENDL | Start a new line in console
33
+ | PRINT_ENDL | Start a new line in console |
34
+
35
+ LOAD and STORE have segment modifiers that can be used as base addresses within functions
36
+
37
+ | Segment | Description |
38
+ | :----------:| -------------|
39
+ | LCL | pointer to first local variable |
40
+ | ARG | pointer to first argument |
41
+
42
+ | Variable Type | Description |
43
+ | :----------:| -------------|
44
+ | static | a fixed address variable, referenced directly |
45
+ | argument | a variable that sits in the working stack of the previous function's frame |
46
+ | local | a local variable within the stack frame of the current function |
47
+
48
+ There is no concept of scope so all variables should be unique
49
+ Variables are declared implicitly upon their first occurance with the exception of arguments
50
+ Variables declared before the first function are static, after the first function they are local
32
51
33
52
The assembler also features Symbols (variables and labels)
34
53
* Variables start with # and are statically allocated at compile time
35
54
* Jump labels start with @
55
+ * Subroutines start with $ and are followed by argument declarations
36
56
37
57
### Planned
38
58
39
59
I plan to add:
40
60
* indexed library function support (executes function at pushed index)
41
- * Subroutines
42
61
* Dynamic memory allocation
43
62
* Support for standard types int float char bool (maybe short, long, double etc) unsigned or signed
44
63
* Built in support for variable length arrays, strings and vectors
0 commit comments