Machine code inerpreter
Go to file
2025-02-02 19:18:01 +05:00
.vscode example 2025-01-20 22:52:44 +05:00
examples started working on parser 2025-01-21 01:17:30 +05:00
src cstr -> str where possible 2025-02-02 19:18:01 +05:00
.gitignore first commit 2024-11-15 09:03:33 +05:00
project.config tcpu 2024-11-15 09:10:17 +05:00
README.md Update README.md 2024-11-15 04:10:54 +00:00

TCPU

Machine code interpreter written in pure C. Can execute programs up to 1 MEGABYTE (1048576 bytes) in size!!!

Building

  1. Install cbuild
  2. cbuild build_exec_dbg
    

Assembly language

Instructions

code name arguments details
00 NOP ignored instruction
01 PUSH dst_register, value_size(bytes), value push constant value into dst_register
02 MOV dst_register, src_register copy value from src_register to dst_register
03 ADD dst_register, src_register dst += src
04 SUB dst_register, src_register dst -= src
05 MUL dst_register, src_register dst *= src
06 DIV dst_register, src_register dst /= src
07 MOD dst_register, src_register dst %= src
08 SYS call system function
09 EXIT stop the program with exit code in ax

Registers

code name size (bits)
00 ax 32
01 bx 32
02 cx 32
03 dx 32

System functions

To call a system function you need to push values to registers and write SYS opcode. The return value of a function will will be avaliable in ax after call.

ax name bx cx dx details
0 read file number buffer pointer buffer size read data from file
1 write file number buffer pointer buffer size write data to file