Skip to content

Commit e9f9b48

Browse files
author
Robert Lindner
authored
Update README.md
1 parent dd4b7af commit e9f9b48

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

README.md

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ Commands:
1616
|:----------:|-------------|
1717
| LITERAL | Push next 4 bytes |
1818
| 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 |
2121
| ADD | Pop b; Pop a; Push a + b |
2222
| SUB | Pop b; Pop a; Push a - b |
2323
| LESS | Pop b; Pop a; Push a < b |
@@ -26,19 +26,38 @@ Commands:
2626
| EQUALS | Pop b; Pop a; Push a == b |
2727
| JMP | Pop a; goto a; |
2828
| 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 |
2931
| PRINT | Pop x; for x Print Pop - temporary, will be a library function based on null terminated strings |
3032
| 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
3251

3352
The assembler also features Symbols (variables and labels)
3453
* Variables start with # and are statically allocated at compile time
3554
* Jump labels start with @
55+
* Subroutines start with $ and are followed by argument declarations
3656

3757
### Planned
3858

3959
I plan to add:
4060
* indexed library function support (executes function at pushed index)
41-
* Subroutines
4261
* Dynamic memory allocation
4362
* Support for standard types int float char bool (maybe short, long, double etc) unsigned or signed
4463
* Built in support for variable length arrays, strings and vectors

0 commit comments

Comments
 (0)