NodeCPU is a "virtual computer" built in NodeJS. While this isn't exactly a proof-of-concept, it is still a bit of an experiment.
This is NodeCPU ABI v0.0.3
. This version includes the new stack.
Opcode | Name | Description | Notes | Link |
---|---|---|---|---|
01 /rn imm16 | mov r,imm16 | Put an immediate into a register | mov | |
02 imm16 | push imm16 | Push an immediate onto the stack | push | |
03 /rn | inc r | Increment a register by 1 | inc | |
04 /rn | pop r | Pop from the stack to a register | pop | |
05 /rn imm16 | add imm16,r | Add immediate to a register | add | |
07 addr16 | jmp addr16 | Jump to an address in memory | jmp | |
08 /r | mov r,r | Put the contents of a register into a register | mov |
Addr | Desc |
---|---|
0x8065 | End of memory |
0x8000 | Stack |
0x4000 | Randomly Accessible Memory (RAM) |
0x0000 | Read-Only Memory (ROM) |
The entry point for programs is 0x0000. ROM can only be modified in "entry mode".
At memory address 0x8000, there are 100 bytes allocated to the stack. You can use push and pop to interact with the stack. The stack itself operates on a FILO1 (First In; Last Out) system and the stack pointer is kept in register SP. When the stack pointer reaches 0x64
it goes back to 0x00
until it reaches existing elements, when it will throw a Segmentation Fault. Be careful!
Mode | Byte | Features | When to use |
---|---|---|---|
Entry | 0x00 | Full access to processor, including ROM | While initialising |
Boot | 0x01 | Access to bootloader and RAM | When booting an operating system |
Protected | 0x02 | Access to RAM | When in an operating system |
To switch modes, put the byte into Register MR.
These registers can be used for any operation, but the recommened uses are as follows:
Name | Recommended Use | RM Nibble |
---|---|---|
RA | Temporary storage/Parameter 1 | 0x1 |
RB | Parameter 2 | 0x2 |
RC | Counter/Parameter 3 | 0x4 |
RD | Result/Parameter 4 | 0x5 |
These registers can only be used for the operation specified.
Name | Use | RM Nibble |
---|---|---|
MR | Mode Register | 0x3 |
SP | Stack Pointer | 0x6 |
Immediate: A value or address in memory 2
RAM: Randomly Accessible Memory
ROM: Read-Only Memory
RM Byte: A byte with two registers (nibbles)3
Footnotes
-
See https://techterms.com/definition/filo for more details. ↩
-
Uses big endian ↩
-
01
: Input = RA, Target = RB. Used for transferring data between registers. In instruction set docs is shown with /r. If the opcode has /rn, the target should be left blank. ↩