Scrap Mechanic

Scrap Mechanic

评价数不足
TimCPU original
   
奖励
收藏
已收藏
取消收藏
文件大小
发表于
更新日期
1.161 MB
2021 年 12 月 9 日 下午 9:36
2021 年 12 月 20 日 上午 3:40
4 项改动说明 ( 查看 )

订阅以下载
TimCPU original

在 smailovtimofey 的 1 个合集中
TimCPU and other machines
23 件物品
描述
Programmable CPU
https://github.com/timofey260/ScrapCPU CPU compiller

Buttons
pwr - power. if power off, code not be read
rst - go counter to 0
hrst - go counter to 0 and reset all registers(pwr need to be off)
next - increase counter by 1 (can press every 2 seconds max)
prev - decrease counter by 1 (can press every 2 seconds max)

err - error sign. lighrs if you try to add register to itself

code understanding

programm accept 4 bytes: OPCODE, ARG1, ARG2, RESULT

last two bytes in OPCODE control ARG1 and ARG2
00 - Both bytes be register values
01 - ARG1 be a register value, ARG2 be a value
10 - ARG2 be a register value, ARG1 be a value
11 - Both bytes be a values

register order:
000 - reg0
001 - reg1
010 - reg2
011 - reg3
100 - reg4
101 - reg5
110 - counter
111 - input/output

Math

first three bytes in OPCODE is math operation choice

000 - add
001 - sub
010 - and
011 - or
100 - not(get only ARG1)
101 - xor
110 - Shift left(if ARG2 = 1 then Shift right)

EXAMPLE:11000000 00000011 00000001 00000001 - add 3 + 1 and return to reg1
EXAMPLE:01000001 00000000 00000011 00000011 - sub reg0 + 3 and return to reg3
EXAMPLE:00000010 00000000 00000001 00000010 - reg0 and reg1 and return to reg2


logic

if 6th bit(32) in OPCODE is on, computer do condition

fitst three bytes is condition:
000 - ==
001 - !=
010 - <
011 - <=
100 - >
101 - >=

if condition is true, counter is set by result

EXAMPLE:11100000 00000011 00000001 00000001 - if 3 == 1 then jump to 0 code line
EXAMPLE:01100001 00000000 00000011 00000011 - if reg0 != 3 then jump to third code line
EXAMPLE:00100010 00000000 00000001 00000010 - if reg0 < reg1 then jump to second code line