Machine code inerpreter
Go to file
2025-07-24 17:49:50 +03:00
.vscode moved collections and string code to tlibc submodule 2025-07-24 17:49:50 +03:00
dependencies moved collections and string code to tlibc submodule 2025-07-24 17:49:50 +03:00
examples implemented flag for comparison result 2025-04-18 03:03:20 +05:00
src moved collections and string code to tlibc submodule 2025-07-24 17:49:50 +03:00
.gitignore first commit 2024-11-15 09:03:33 +05:00
.gitmodules moved collections and string code to tlibc submodule 2025-07-24 17:49:50 +03:00
project.config moved collections and string code to tlibc submodule 2025-07-24 17:49:50 +03:00
README.md moved collections and string code to tlibc submodule 2025-07-24 17:49:50 +03:00
TODO.md refactored registers 2025-04-18 02:46:46 +05:00

TCPU

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

Building

  1. Clone repo
    git clone --recurse-submodules --depth 1 https://timerix.ddns.net/git/Timerix/tcpu.git
    
  2. Install cbuild
  3. Install SDL3 and SDL3_image from package manager or source.
  4. cbuild build_exec_dbg
    

Assembly language

Registers

name code size (bits)
rax 0x01 64
eax 0x02 32
ax 0x04 16
al 0x07 8
ah 0x08 8
rbx 0x11 64
ebx 0x12 32
bx 0x14 16
bl 0x17 8
bh 0x18 8
rcx 0x21 64
ecx 0x22 32
cx 0x24 16
cl 0x27 8
ch 0x28 8
rdx 0x31 64
edx 0x32 32
dx 0x34 16
dl 0x37 8
dh 0x38 8

Instructions

name arguments details
NOP ignored instruction
EXIT stop the program with exit code in eax
SYS call system function
MOVC dst_register, const_value push constant value into dst_register
MOVR dst_register, src_register copy value from src_register to dst_register
ADD dst_register, src_register dst += src
SUB dst_register, src_register dst -= src
MUL dst_register, src_register dst *= src
DIV dst_register, src_register dst /= src
MOD dst_register, src_register dst %= src
EQ dst_register, src_register cmp_flag = dst == src
NE dst_register, src_register cmp_flag = dst != src
LT dst_register, src_register cmp_flag = dst < src
LE dst_register, src_register cmp_flag = dst <= src
GT dst_register, src_register cmp_flag = dst > src
GE dst_register, src_register cmp_flag = dst >= src
NOT dst_register dst = !dst
INV dst_register dst = ~dst
OR dst_register, src_register dst = dst | src
XOR dst_register, src_register dst = dst ^ src
AND dst_register, src_register dst = dst & src
JMP dst_address_const goto dst
JNZ dst_address_const if (cmp_flag != 0) goto dst
JZ dst_address_const if (cmp_flag == 0) goto dst

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.

name al ah rbx ecx details
read 0 file number buffer pointer buffer size read data from file
write 1 file number buffer pointer buffer size write data to file